You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(97) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(127) |
Feb
(34) |
Mar
(16) |
Apr
(26) |
May
(55) |
Jun
(107) |
Jul
(36) |
Aug
(72) |
Sep
(90) |
Oct
(41) |
Nov
(27) |
Dec
(13) |
2008 |
Jan
(37) |
Feb
(39) |
Mar
(98) |
Apr
(115) |
May
(134) |
Jun
(120) |
Jul
(86) |
Aug
(149) |
Sep
(68) |
Oct
(66) |
Nov
(104) |
Dec
(49) |
2009 |
Jan
(131) |
Feb
(132) |
Mar
(125) |
Apr
(172) |
May
(161) |
Jun
(43) |
Jul
(47) |
Aug
(38) |
Sep
(18) |
Oct
(6) |
Nov
(1) |
Dec
(15) |
2010 |
Jan
(21) |
Feb
(8) |
Mar
(10) |
Apr
(4) |
May
(9) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(4) |
2011 |
Jan
(23) |
Feb
(10) |
Mar
(13) |
Apr
(3) |
May
|
Jun
(19) |
Jul
(11) |
Aug
(22) |
Sep
|
Oct
(4) |
Nov
(2) |
Dec
(12) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
(7) |
Apr
(3) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(30) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(8) |
2013 |
Jan
(3) |
Feb
(40) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(12) |
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
From: <ls...@us...> - 2007-01-27 21:37:52
|
Revision: 3094 http://jnode.svn.sourceforge.net/jnode/?rev=3094&view=rev Author: lsantha Date: 2007-01-27 13:37:48 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Fixed ClassCastException. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/classmgr/VmType.java Modified: trunk/core/src/core/org/jnode/vm/classmgr/VmType.java =================================================================== --- trunk/core/src/core/org/jnode/vm/classmgr/VmType.java 2007-01-27 13:40:17 UTC (rev 3093) +++ trunk/core/src/core/org/jnode/vm/classmgr/VmType.java 2007-01-27 21:37:48 UTC (rev 3094) @@ -661,7 +661,7 @@ if (javaClass == null) { if (isBuildEnv) { try { - javaClassHolder.set(Class.forName(getName())); + javaClassHolder.set((Class<T>) Class.forName(getName())); } catch (ClassNotFoundException ex) { /* ignore */ throw new NoClassDefFoundError(getName()); } @@ -1832,8 +1832,6 @@ /** * Resolve all constant references in the constants pool - * - * @param clc */ public final void resolveCpRefs() { if (!resolvedCpRefs) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-27 13:40:18
|
Revision: 3093 http://jnode.svn.sourceforge.net/jnode/?rev=3093&view=rev Author: lsantha Date: 2007-01-27 05:40:17 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Replaced StringBuffer with StringBuilder. Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java trunk/shell/src/shell/org/jnode/shell/help/argument/OptionArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2007-01-27 12:57:10 UTC (rev 3092) +++ trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2007-01-27 13:40:17 UTC (rev 3093) @@ -18,7 +18,7 @@ * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + package org.jnode.shell.command; import java.io.InputStream; @@ -34,7 +34,7 @@ /** * Shell command to view threads or a specific thread. - * + * * @author Ewout Prangsma (ep...@us...) * @author Martin Husted Hartvig (ha...@jn...) */ @@ -73,15 +73,13 @@ } private void showGroup(ThreadGroup grp, PrintStream out, String threadName) { - StringBuffer stringBuffer; - if (threadName == null // preserve compatible behavior when piped && out == System.out) { grp.list(); return; } - + if (threadName != null) { out.print(group); out.println(grp.getName()); @@ -92,45 +90,40 @@ grp.enumerate(ts); + for (int i = 0; i < max; i++) { + final Thread t = ts[i]; + if (t != null) { + if ((threadName == null) || threadName.equals(t.getName())) { + out.print(slash_t); + StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < max; i++) { - final Thread t = ts[i]; - if (t != null) { - if ((threadName == null) || threadName.equals(t.getName())) { - out.print(slash_t); - stringBuffer = new StringBuffer(); + buffer.append(t.getId()); + buffer.append(seperator); + buffer.append(t.getName()); + buffer.append(seperator); + buffer.append(t.getPriority()); + buffer.append(seperator); + buffer.append(t.getVmThread().getThreadStateName()); - stringBuffer.append(t.getId()); - stringBuffer.append(seperator); - stringBuffer.append(t.getName()); - stringBuffer.append(seperator); - stringBuffer.append(t.getPriority()); - stringBuffer.append(seperator); - stringBuffer.append(t.getVmThread().getThreadStateName()); + out.println(buffer.toString()); + if (threadName != null) { + final Object[] trace = VmThread.getStackTrace(t.getVmThread()); + final int traceLen = trace.length; + for (int k = 0; k < traceLen; k++) { + buffer = new StringBuilder(); + buffer.append(slash_t); + buffer.append(slash_t); + buffer.append(trace[k]); - out.println(stringBuffer.toString()); - stringBuffer = null; + out.println(buffer.toString()); + } - if (threadName != null) { - final Object[] trace = VmThread.getStackTrace(t.getVmThread()); - final int traceLen = trace.length; - for (int k = 0; k < traceLen; k++) { - stringBuffer = new StringBuffer(); - stringBuffer.append(slash_t); - stringBuffer.append(slash_t); - stringBuffer.append(trace[k]); + return; + } + } + } + } - out.println(stringBuffer.toString()); - - stringBuffer = null; - } - - return; - } - } - } - } - final int gmax = grp.activeGroupCount() * 2; final ThreadGroup[] tgs = new ThreadGroup[gmax]; grp.enumerate(tgs); Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2007-01-27 12:57:10 UTC (rev 3092) +++ trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2007-01-27 13:40:17 UTC (rev 3093) @@ -190,7 +190,7 @@ throws PluginException { final ArrayList<String> rows = new ArrayList<String>(); for (PluginDescriptor descr : mgr.getRegistry()) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(descr.getId()); sb.append("; state "); sb.append((descr.getPlugin().isActive())?"active":"inactive"); Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/OptionArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/OptionArgument.java 2007-01-27 12:57:10 UTC (rev 3092) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/OptionArgument.java 2007-01-27 13:40:17 UTC (rev 3093) @@ -88,7 +88,7 @@ * @see java.lang.Object#toString() */ public String toString() { - final StringBuffer sb = new StringBuffer(); + final StringBuilder sb = new StringBuilder(); sb.append("Options: "); for (Option option : options) { sb.append(", "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-27 12:57:12
|
Revision: 3092 http://jnode.svn.sourceforge.net/jnode/?rev=3092&view=rev Author: lsantha Date: 2007-01-27 04:57:10 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Replaced StringBuffer with StringBuilder. Modified Paths: -------------- trunk/core/src/core/org/jnode/util/Counter.java trunk/core/src/core/org/jnode/vm/bytecode/BasicBlock.java trunk/core/src/core/org/jnode/vm/bytecode/TypeStack.java trunk/core/src/core/org/jnode/vm/compiler/ir/IRControlFlowGraph.java trunk/core/src/core/org/jnode/vm/compiler/ir/PhiOperand.java trunk/core/src/core/org/jnode/vm/scheduler/IRQThread.java trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86RegisterPool.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/ItemStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/X86RegisterPool.java Modified: trunk/core/src/core/org/jnode/util/Counter.java =================================================================== --- trunk/core/src/core/org/jnode/util/Counter.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/util/Counter.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -100,10 +100,10 @@ * @see java.lang.Object#toString() */ public String toString() { - StringBuffer stringBuffer = new StringBuffer(getName()); - stringBuffer.append(is); - stringBuffer.append(counter); + StringBuilder sb = new StringBuilder(getName()); + sb.append(is); + sb.append(counter); - return stringBuffer.toString(); + return sb.toString(); } } Modified: trunk/core/src/core/org/jnode/vm/bytecode/BasicBlock.java =================================================================== --- trunk/core/src/core/org/jnode/vm/bytecode/BasicBlock.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/bytecode/BasicBlock.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -105,7 +105,7 @@ * @return String */ public String toString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); buf.append(startPC); buf.append('-'); buf.append(endPC); @@ -120,7 +120,7 @@ return buf.toString(); } - private void addEntryBlockInfo(StringBuffer buf) { + private void addEntryBlockInfo(StringBuilder buf) { boolean first = true; for (BasicBlock bb : entryBlocks) { if (first) { Modified: trunk/core/src/core/org/jnode/vm/bytecode/TypeStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/bytecode/TypeStack.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/bytecode/TypeStack.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -158,7 +158,7 @@ * @see java.lang.Object#toString() */ public String toString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); buf.append('{'); for (int i = 0; i < tos; i++) { if (i > 0) { Modified: trunk/core/src/core/org/jnode/vm/compiler/ir/IRControlFlowGraph.java =================================================================== --- trunk/core/src/core/org/jnode/vm/compiler/ir/IRControlFlowGraph.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/compiler/ir/IRControlFlowGraph.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -406,7 +406,7 @@ } public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (IRBasicBlock<T> bb : this) { sb.append(bb.toString()); sb.append(":\n predecessors:"); Modified: trunk/core/src/core/org/jnode/vm/compiler/ir/PhiOperand.java =================================================================== --- trunk/core/src/core/org/jnode/vm/compiler/ir/PhiOperand.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/compiler/ir/PhiOperand.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -58,7 +58,7 @@ } public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("phi("); int n = sources.size(); for (int i=0; i<n; i+=1) { Modified: trunk/core/src/core/org/jnode/vm/scheduler/IRQThread.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/IRQThread.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/scheduler/IRQThread.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -194,7 +194,7 @@ * @return String */ public String toString() { - final StringBuffer b = new StringBuffer(); + final StringBuilder b = new StringBuilder(); if (shared) { b.append("shared "); } Modified: trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -148,7 +148,7 @@ */ public String getVendor() { if (vendor == null) { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); intToString(buf, data[1]); intToString(buf, data[3]); intToString(buf, data[2]); @@ -173,7 +173,7 @@ return getVendor().equals(X86Vendor.AMD.getId()); } - private final void intToString(StringBuffer buf, int value) { + private final void intToString(StringBuilder buf, int value) { buf.append((char) (value & 0xFF)); buf.append((char) ((value >> 8) & 0xFF)); buf.append((char) ((value >> 16) & 0xFF)); @@ -310,7 +310,7 @@ * @return The available features. */ private final String getFeatureString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); getFeatureString(buf, FEAT_FPU, "FPU"); getFeatureString(buf, FEAT_VME, "VME"); getFeatureString(buf, FEAT_DE, "DE"); @@ -347,7 +347,7 @@ return buf.toString(); } - private final void getFeatureString(StringBuffer buf, int feature, String featName) { + private final void getFeatureString(StringBuilder buf, int feature, String featName) { if (hasFeature(feature)) { if (buf.length() > 0) { buf.append(','); @@ -356,7 +356,7 @@ } } - private final void getFeatureString(StringBuffer buf, long feature, String featName) { + private final void getFeatureString(StringBuilder buf, long feature, String featName) { if (hasFeature(feature)) { if (buf.length() > 0) { buf.append(','); @@ -371,7 +371,7 @@ * @see java.lang.Object#toString() */ public String toString() { - final StringBuffer sb = new StringBuffer(); + final StringBuilder sb = new StringBuilder(); sb.append("CPU:"); sb.append(" name:"); sb.append(getName()); sb.append(" family:"); sb.append(getFamily()); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -170,7 +170,7 @@ if (tos == 0) { return "EMPTY"; } - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < tos; i++) { if (i != 0) { buf.append(','); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -404,7 +404,7 @@ if (tos == 0) { return "EMPTY"; } - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < tos; i++) { if (i != 0) { buf.append(','); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86RegisterPool.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86RegisterPool.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86RegisterPool.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -274,7 +274,7 @@ * @see java.lang.Object#toString() */ public final String toString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < regCount; i++) { buf.append(registers[i].toString()); buf.append("\n"); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/ItemStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/ItemStack.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/ItemStack.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -170,7 +170,7 @@ if (tos == 0) { return "EMPTY"; } - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < tos; i++) { if (i != 0) { buf.append(','); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -404,7 +404,7 @@ if (tos == 0) { return "EMPTY"; } - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < tos; i++) { if (i != 0) { buf.append(','); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/X86RegisterPool.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/X86RegisterPool.java 2007-01-27 11:43:17 UTC (rev 3091) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1b/X86RegisterPool.java 2007-01-27 12:57:10 UTC (rev 3092) @@ -274,7 +274,7 @@ * @see java.lang.Object#toString() */ public final String toString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < regCount; i++) { buf.append(registers[i].toString()); buf.append("\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-27 11:43:22
|
Revision: 3091 http://jnode.svn.sourceforge.net/jnode/?rev=3091&view=rev Author: lsantha Date: 2007-01-27 03:43:17 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/java/awt/java2d/AbstractGraphics2D.java trunk/core/src/classpath/java/java/lang/InheritableThreadLocal.java trunk/core/src/classpath/java/java/lang/StringBuffer.java trunk/core/src/classpath/java/java/lang/ThreadLocal.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectionKeyImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectorImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/VMChannelOwner.java trunk/core/src/classpath/java/java/util/concurrent/locks/ReentrantReadWriteLock.java Modified: trunk/core/src/classpath/gnu/gnu/java/awt/java2d/AbstractGraphics2D.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/java2d/AbstractGraphics2D.java 2007-01-27 10:06:33 UTC (rev 3090) +++ trunk/core/src/classpath/gnu/gnu/java/awt/java2d/AbstractGraphics2D.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -166,14 +166,14 @@ * Caches certain shapes to avoid massive creation of such Shapes in * the various draw* and fill* methods. */ - private static final ThreadLocal shapeCache = - new ThreadLocal(); + private static final ThreadLocal<ShapeCache> shapeCache = + new ThreadLocal<ShapeCache>(); /** * The scanline converters by thread. */ - private static final ThreadLocal scanlineConverters = - new ThreadLocal(); + private static final ThreadLocal<ScanlineConverter> scanlineConverters = + new ThreadLocal<ScanlineConverter>(); /** * The transformation for this Graphics2D instance @@ -1947,7 +1947,7 @@ */ private ShapeCache getShapeCache() { - ShapeCache sc = (ShapeCache) shapeCache.get(); + ShapeCache sc = shapeCache.get(); if (sc == null) { sc = new ShapeCache(); @@ -1963,7 +1963,7 @@ */ private ScanlineConverter getScanlineConverter() { - ScanlineConverter sc = (ScanlineConverter) scanlineConverters.get(); + ScanlineConverter sc = scanlineConverters.get(); if (sc == null) { sc = new ScanlineConverter(); Added: trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectionKeyImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectionKeyImpl.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectionKeyImpl.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -0,0 +1,189 @@ +/* KqueueSelectionKeyImpl.java -- selection key for kqueue/kevent. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.nio; + + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SelectableChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.spi.AbstractSelectionKey; + +/** + * @author Casey Marshall (cs...@gn...) + */ +public class KqueueSelectionKeyImpl extends AbstractSelectionKey +{ + int interestOps; + int readyOps; + int activeOps = 0; + int key; + int fd; + + /** The selector we were created for. */ + private final KqueueSelectorImpl selector; + + /** The channel we are attached to. */ + private final SelectableChannel channel; + + private final VMChannelOwner natChannel; + + public KqueueSelectionKeyImpl(KqueueSelectorImpl selector, + SelectableChannel channel) + { + this.selector = selector; + this.channel = channel; + natChannel = (VMChannelOwner) channel; + interestOps = 0; + readyOps = 0; + } + + /* (non-Javadoc) + * @see java.nio.channels.SelectionKey#channel() + */ + //@Override + public SelectableChannel channel() + { + return channel; + } + + /* (non-Javadoc) + * @see java.nio.channels.SelectionKey#interestOps() + */ + //@Override + public int interestOps() + { + return interestOps; + } + + /* (non-Javadoc) + * @see java.nio.channels.SelectionKey#interestOps(int) + */ + //@Override + public SelectionKey interestOps(int ops) + { + if (!isValid()) + throw new IllegalStateException("key is invalid"); + if ((ops & ~channel.validOps()) != 0) + throw new IllegalArgumentException("channel does not support all operations"); + + selector.setInterestOps(this, ops); + return this; + } + + /* (non-Javadoc) + * @see java.nio.channels.SelectionKey#readyOps() + */ + //@Override + public int readyOps() + { + return readyOps; + } + + /* (non-Javadoc) + * @see java.nio.channels.SelectionKey#selector() + */ + //@Override + public Selector selector() + { + return selector; + } + + public String toString() + { + if (!isValid()) + return super.toString() + " [ fd: " + fd + " <<invalid>> ]"; + return super.toString() + " [ fd: " + fd + " interest ops: {" + + ((interestOps & OP_ACCEPT) != 0 ? " OP_ACCEPT" : "") + + ((interestOps & OP_CONNECT) != 0 ? " OP_CONNECT" : "") + + ((interestOps & OP_READ) != 0 ? " OP_READ" : "") + + ((interestOps & OP_WRITE) != 0 ? " OP_WRITE" : "") + + " }; ready ops: {" + + ((readyOps & OP_ACCEPT) != 0 ? " OP_ACCEPT" : "") + + ((readyOps & OP_CONNECT) != 0 ? " OP_CONNECT" : "") + + ((readyOps & OP_READ) != 0 ? " OP_READ" : "") + + ((readyOps & OP_WRITE) != 0 ? " OP_WRITE" : "") + + " } ]"; + } + + public int hashCode() + { + return fd; + } + + public boolean equals(Object o) + { + if (!(o instanceof KqueueSelectionKeyImpl)) + return false; + KqueueSelectionKeyImpl that = (KqueueSelectionKeyImpl) o; + return that.fd == this.fd && that.channel.equals(this.channel); + } + + + boolean isReadActive() + { + return (activeOps & (OP_READ | OP_ACCEPT)) != 0; + } + + boolean isReadInterested() + { + return (interestOps & (OP_READ | OP_ACCEPT)) != 0; + } + + boolean isWriteActive() + { + return (activeOps & (OP_WRITE | OP_CONNECT)) != 0; + } + + boolean isWriteInterested() + { + return (interestOps & (OP_WRITE | OP_CONNECT)) != 0; + } + + boolean needCommitRead() + { + return isReadActive() == (!isReadInterested()); + } + + boolean needCommitWrite() + { + return isWriteActive() == (!isWriteInterested()); + } +} Added: trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectorImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectorImpl.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectorImpl.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -0,0 +1,527 @@ +/* KqueueSelectorImpl.java -- Selector for systems with kqueue event notification. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.nio; + + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.ClosedSelectorException; +import java.nio.channels.SelectableChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.spi.AbstractSelectableChannel; +import java.nio.channels.spi.AbstractSelector; +import java.nio.channels.spi.SelectorProvider; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * A {@link Selector} implementation that uses the <code>kqueue</code> + * event notification facility. + * + * @author Casey Marshall (cs...@gn...) + */ +public class KqueueSelectorImpl extends AbstractSelector +{ + // Prepended underscore to field name to make it distinct + // from the method with the similar name. + private static final int _sizeof_struct_kevent; + + private static final int MAX_DOUBLING_CAPACITY = 16384; + private static final int CAP_INCREMENT = 1024; + private static final int INITIAL_CAPACITY; + + static + { + try + { + System.loadLibrary("javanio"); + } + catch (Exception x) + { + x.printStackTrace(); + } + + if (kqueue_supported ()) + _sizeof_struct_kevent = sizeof_struct_kevent(); + else + _sizeof_struct_kevent = -1; + INITIAL_CAPACITY = 16 * _sizeof_struct_kevent; + } + + /** + * Tell if kqueue-based selectors are supported on this system. + * + * @return True if this system has kqueue support, and support for it was + * compiled in to Classpath. + */ + public static native boolean kqueue_supported(); + + /* Our native file descriptor. */ + private int kq; + + private HashMap/*<Integer,KqueueSelectionKeyImpl>*/ keys; + private HashSet/*<KqueueSelectionKeyImpl>*/ selected; + private Thread blockedThread; + private ByteBuffer events; + + private static final int OP_ACCEPT = SelectionKey.OP_ACCEPT; + private static final int OP_CONNECT = SelectionKey.OP_CONNECT; + private static final int OP_READ = SelectionKey.OP_READ; + private static final int OP_WRITE = SelectionKey.OP_WRITE; + + public KqueueSelectorImpl(SelectorProvider provider) throws IOException + { + super(provider); + kq = implOpen(); + keys = new HashMap/*<KqueueSelectionKeyImpl>*/(); + events = ByteBuffer.allocateDirect(INITIAL_CAPACITY); + } + + protected void implCloseSelector() throws IOException + { + implClose(kq); + kq = -1; + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#keys() + */ + public Set keys() + { + if (!isOpen()) + throw new ClosedSelectorException(); + + return new HashSet(keys.values()); + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#select() + */ + public int select() throws IOException + { + return doSelect(-1); + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#select(long) + */ + public int select(long timeout) throws IOException + { + if (timeout == 0) + timeout = -1; + return doSelect(timeout); + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#selectedKeys() + */ + public Set selectedKeys() + { + if (!isOpen()) + throw new ClosedSelectorException(); + + return selected; + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#selectNow() + */ + public int selectNow() throws IOException + { + return doSelect(0); + } + + /* (non-Javadoc) + * @see java.nio.channels.Selector#wakeup() + */ + public Selector wakeup() + { + if (blockedThread != null) + blockedThread.interrupt(); + return this; + } + + public String toString() + { + return super.toString() + " [ fd: " + kq + " ]"; + } + + public boolean equals(Object o) + { + if (!(o instanceof KqueueSelectorImpl)) + return false; + + return ((KqueueSelectorImpl) o).kq == kq; + } + + int doSelect(long timeout) throws IOException + { + Set cancelled = cancelledKeys(); + synchronized (cancelled) + { + synchronized (keys) + { + for (Iterator it = cancelled.iterator(); it.hasNext(); ) + { + KqueueSelectionKeyImpl key = (KqueueSelectionKeyImpl) it.next(); + key.interestOps = 0; + } + + int events_size = (2 * _sizeof_struct_kevent) * keys.size(); + int num_events = 0; + + for (Iterator it = keys.entrySet().iterator(); it.hasNext(); ) + { + Map.Entry e = (Map.Entry) it.next(); + KqueueSelectionKeyImpl key = (KqueueSelectionKeyImpl) e.getValue(); + + SelectableChannel ch = key.channel(); + if (ch instanceof VMChannelOwner) + { + if (!((VMChannelOwner) ch).getVMChannel().getState().isValid()) + { + // closed channel; removed from kqueue automatically. + it.remove(); + continue; + } + } + + // If this key is registering a read filter, add it to the buffer. + if (key.needCommitRead()) + { + kevent_set(events, num_events, key.fd, + key.interestOps & (OP_READ | OP_ACCEPT), + key.activeOps & (OP_READ | OP_ACCEPT), key.key); + num_events++; + } + + // If this key is registering a write filter, add it to the buffer. + if (key.needCommitWrite()) + { + kevent_set(events, num_events, key.fd, + key.interestOps & (OP_WRITE | OP_CONNECT), + key.activeOps & (OP_WRITE | OP_CONNECT), key.key); + num_events++; + } + } + events.rewind().limit(events.capacity()); + + //System.out.println("dump of keys to select:"); + //dump_selection_keys(events.duplicate()); + + int n = 0; + try + { + //System.out.println("[" + kq + "] kevent enter selecting from " + keys.size()); + begin(); + blockedThread = Thread.currentThread(); + if (blockedThread.isInterrupted()) + timeout = 0; + n = kevent(kq, events, num_events, + events.capacity() / _sizeof_struct_kevent, timeout); + } + finally + { + end(); + blockedThread = null; + Thread.interrupted(); + //System.out.println("[" + kq + "kevent exit selected " + n); + } + + //System.out.println("dump of keys selected:"); + //dump_selection_keys((ByteBuffer) events.duplicate().limit(n * _sizeof_struct_kevent)); + + // Commit the operations we've just added in the call to kevent. + for (Iterator it = keys.values().iterator(); it.hasNext(); ) + { + KqueueSelectionKeyImpl key = (KqueueSelectionKeyImpl) it.next(); + key.activeOps = key.interestOps; + } + + selected = new HashSet/*<KqueueSelectionKeyImpl>*/(n); + int x = 0; + for (int i = 0; i < n; i++) + { + events.position(x).limit(x + _sizeof_struct_kevent); + x += _sizeof_struct_kevent; + int y = fetch_key(events.slice()); + KqueueSelectionKeyImpl key = + (KqueueSelectionKeyImpl) keys.get(new Integer(y)); + + if (key == null) + { + System.out.println("WARNING! no key found for selected key " + y); + continue; + } + // Keys that have been cancelled may be returned here; don't + // add them to the selected set. + if (!key.isValid()) + continue; + key.readyOps = ready_ops(events.slice(), key.interestOps); + selected.add(key); + } + + // Finally, remove the cancelled keys. + for (Iterator it = cancelled.iterator(); it.hasNext(); ) + { + KqueueSelectionKeyImpl key = (KqueueSelectionKeyImpl) it.next(); + keys.remove(new Integer(key.key)); + deregister(key); + it.remove(); + } + + reallocateBuffer(); + + return selected.size(); + } + } + } + + protected SelectionKey register(AbstractSelectableChannel channel, + int interestOps, + Object attachment) + { + int native_fd = -1; + try + { + if (channel instanceof VMChannelOwner) + native_fd = ((VMChannelOwner) channel).getVMChannel() + .getState().getNativeFD(); + else + throw new IllegalArgumentException("cannot handle channel type " + + channel.getClass().getName()); + } + catch (IOException ioe) + { + throw new IllegalArgumentException("channel is closed or invalid"); + } + + KqueueSelectionKeyImpl result = new KqueueSelectionKeyImpl(this, channel); + result.interestOps = interestOps; + result.attach(attachment); + result.fd = native_fd; + result.key = System.identityHashCode(result); + synchronized (keys) + { + while (keys.containsKey(new Integer(result.key))) + result.key++; + keys.put(new Integer(result.key), result); + reallocateBuffer(); + } + return result; + } + + void setInterestOps(KqueueSelectionKeyImpl key, int ops) + { + synchronized (keys) + { + key.interestOps = ops; + } + } + + /** + * Reallocate the events buffer. This is the destination buffer for + * events returned by kevent. This method will: + * + * * Grow the buffer if there is insufficent space for all registered + * events. + * * Shrink the buffer if it is more than twice the size needed. + * + */ + private void reallocateBuffer() + { + synchronized (keys) + { + if (events.capacity() < (2 * _sizeof_struct_kevent) * keys.size()) + { + int cap = events.capacity(); + if (cap >= MAX_DOUBLING_CAPACITY) + cap += CAP_INCREMENT; + else + cap = cap << 1; + + events = ByteBuffer.allocateDirect(cap); + } + else if (events.capacity() > 4 * (_sizeof_struct_kevent) * keys.size() + 1 + && events.capacity() > INITIAL_CAPACITY) + { + int cap = events.capacity(); + cap = cap >>> 1; + events = ByteBuffer.allocateDirect(cap); + } + } + } + + //synchronized void updateOps(KqueueSelectionKeyImpl key, int interestOps) + //{ + // updateOps(key, interestOps, 0, false); + //} + + /*void updateOps(KqueueSelectionKeyImpl key, int interestOps, + int activeOps, int fd) + { + //System.out.println(">> updating kqueue selection key:"); + //dump_selection_keys(key.nstate.duplicate()); + //System.out.println("<<"); + synchronized (keys) + { + kevent_set(key.nstate, fd, interestOps, activeOps, key.key); + } + //System.out.println(">> updated kqueue selection key:"); + //dump_selection_keys(key.nstate.duplicate()); + //System.out.println("<<"); + }*/ + + private void dump_selection_keys(ByteBuffer keys) + { + // WARNING! This method is not guaranteed to be portable! This works + // on darwin/x86, but the sizeof and offsetof these fields may be + // different on other platforms! + int i = 0; + keys.order(ByteOrder.nativeOrder()); + while (keys.hasRemaining()) + { + System.out.println("struct kevent { ident: " + + Integer.toString(keys.getInt()) + + " filter: " + + Integer.toHexString(keys.getShort() & 0xFFFF) + + " flags: " + + Integer.toHexString(keys.getShort() & 0xFFFF) + + " fflags: " + + Integer.toHexString(keys.getInt()) + + " data: " + + Integer.toHexString(keys.getInt()) + + " udata: " + + Integer.toHexString(keys.getInt()) + + " }"); + } + } + + /** + * Return the size of a <code>struct kevent</code> on this system. + * + * @return The size of <code>struct kevent</code>. + */ + private static native int sizeof_struct_kevent(); + + /** + * Opens a kqueue descriptor. + * + * @return The new kqueue descriptor. + * @throws IOException If opening fails. + */ + private static native int implOpen() throws IOException; + + /** + * Closes the kqueue file descriptor. + * + * @param kq The kqueue file descriptor. + * @throws IOException + */ + private static native void implClose(int kq) throws IOException; + + /** + * Initialize the specified native state for the given interest ops. + * + * @param nstate The native state structures; in this buffer should be + * the <code>struct kevent</code>s created for a key. + * @param fd The file descriptor. If 0, the native FD is unmodified. + * @param interestOps The operations to enable. + * @param key A unique key that will reference the associated key later. + * @param delete Set to true if this event should be deleted from the + * kqueue (if false, this event is added/updated). + */ + private static native void kevent_set(ByteBuffer nstate, int i, int fd, + int interestOps, int activeOps, int key); + + /** + * Poll for events. The source events are stored in <code>events</code>, + * which is also where polled events will be placed. + * + * @param events The events to poll. This buffer is also the destination + * for events read from the queue. + * @param nevents The number of events to poll (that is, the number of + * events in the <code>events</code> buffer). + * @param nout The maximum number of events that may be returned. + * @param timeout The timeout. A timeout of -1 returns immediately; a timeout + * of 0 waits indefinitely. + * @return The number of events read. + */ + private static native int kevent(int kq, ByteBuffer events, int nevents, + int nout, long timeout); + + /** + * Fetch a polled key from a native state buffer. For each kevent key we + * create, we put the native state info (one or more <code>struct + * kevent</code>s) in that key's {@link KqueueSelectionKeyImpl#nstate} + * buffer, and place the pointer of the key in the <code>udata</code> field + * of that structure. This method fetches that pointer from the given + * buffer (assumed to be a <code>struct kqueue</code>) and returns it. + * + * @param nstate The buffer containing the <code>struct kqueue</code> to read. + * @return The key object. + */ + private static native int fetch_key(ByteBuffer nstate); + + /** + * Fetch the ready ops of the associated native state. That is, this + * inspects the first argument as a <code>struct kevent</code>, looking + * at its operation (the input is assumed to have been returned via a + * previous call to <code>kevent</code>), and translating that to the + * appropriate Java bit set, based on the second argument. + * + * @param nstate The native state. + * @param interestOps The enabled operations for the key. + * @return The bit set representing the ready operations. + */ + private static native int ready_ops(ByteBuffer nstate, int interestOps); + + /** + * Check if kevent returned EV_EOF for a selection key. + * + * @param nstate The native state. + * @return True if the kevent call returned EOF. + */ + private static native boolean check_eof(ByteBuffer nstate); +} Added: trunk/core/src/classpath/gnu/gnu/java/nio/VMChannelOwner.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/VMChannelOwner.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/java/nio/VMChannelOwner.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -0,0 +1,57 @@ +/* NativeFD.java -- interface for Channels that have an underlying file descriptor. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.nio; + +/** + * This interface is meant to be implemented by any {@link Channel} + * implementation we support that uses a platform-specific {@link VMChannel} + * at their core. This is primarily used by {@link Selector} implementations, + * for easier access to the native state. + * + * @author Casey Marshall (cs...@gn...) + */ +interface VMChannelOwner +{ + /** + * Return the underlying platform-specific Channel instance. + * + * @return The platform channel object. + */ + VMChannel getVMChannel(); +} Modified: trunk/core/src/classpath/java/java/lang/InheritableThreadLocal.java =================================================================== --- trunk/core/src/classpath/java/java/lang/InheritableThreadLocal.java 2007-01-27 10:06:33 UTC (rev 3090) +++ trunk/core/src/classpath/java/java/lang/InheritableThreadLocal.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -53,12 +53,15 @@ * * @author Mark Wielaard (ma...@kl...) * @author Eric Blake (eb...@em...) + * @author Tom Tromey (tr...@re...) + * @author Andrew John Hughes (gnu...@me...) * @see ThreadLocal * @since 1.2 * @status updated to 1.4 */ public class InheritableThreadLocal extends ThreadLocal { + /** * Creates a new InheritableThreadLocal that has no values associated * with it yet. Modified: trunk/core/src/classpath/java/java/lang/StringBuffer.java =================================================================== --- trunk/core/src/classpath/java/java/lang/StringBuffer.java 2007-01-27 10:06:33 UTC (rev 3090) +++ trunk/core/src/classpath/java/java/lang/StringBuffer.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -72,8 +72,12 @@ * @since 1.0 * @status updated to 1.4 */ -public final class StringBuffer implements Serializable, CharSequence +public final class StringBuffer + implements Serializable, CharSequence, Appendable { + // Implementation note: if you change this class, you usually will + // want to change StringBuilder as well. + /** * Compatible with JDK 1.0+. */ @@ -148,21 +152,22 @@ } /** - * Create a new <code>StringBuffer</code> with the characters from the + * Create a new <code>StringBuffer</code> with the characters in the * specified <code>CharSequence</code>. Initial capacity will be the - * size of the CharSequence plus 16. + * length of the sequence plus 16; if the sequence reports a length + * less than or equal to 0, then the initial capacity will be 16. * - * @param sequence the <code>String</code> to convert + * @param seq the initializing <code>CharSequence</code> * @throws NullPointerException if str is null - * * @since 1.5 */ - public StringBuffer(CharSequence sequence) + public StringBuffer(CharSequence seq) { - count = Math.max(0, sequence.length()); + int len = seq.length(); + count = len <= 0 ? 0 : len; value = new char[count + DEFAULT_CAPACITY]; - for (int i = 0; i < count; ++i) - value[i] = sequence.charAt(i); + for (int i = 0; i < len; ++i) + value[i] = seq.charAt(i); } /** @@ -391,46 +396,6 @@ } /** - * Append the <code>CharSequence</code> value of the argument to this - * <code>StringBuffer</code>. - * - * @param sequence the <code>CharSequence</code> to append - * @return this <code>StringBuffer</code> - * @see #append(Object) - * @since 1.5 - */ - public synchronized StringBuffer append(CharSequence sequence) - { - if (sequence == null) - sequence = "null"; - return append(sequence, 0, sequence.length()); - } - - /** - * Append the specified subsequence of the <code>CharSequence</code> - * argument to this <code>StringBuffer</code>. - * - * @param sequence the <code>CharSequence</code> to append - * @param start the starting index - * @param end one past the ending index - * @return this <code>StringBuffer</code> - * @see #append(Object) - * @since 1.5 - */ - public synchronized StringBuffer append(CharSequence sequence, - int start, int end) - { - if (sequence == null) - sequence = "null"; - if (start < 0 || end < 0 || start > end || end > sequence.length()) - throw new IndexOutOfBoundsException(); - ensureCapacity_unsynchronized(this.count + end - start); - for (int i = start; i < end; ++i) - value[count++] = sequence.charAt(i); - return this; - } - - /** * Append the <code>char</code> array to this <code>StringBuffer</code>. * This is similar (but more efficient) than * <code>append(new String(data))</code>, except in the case of null. @@ -470,6 +435,25 @@ } /** + * Append the code point to this <code>StringBuffer</code>. + * This is like #append(char), but will append two characters + * if a supplementary code point is given. + * + * @param code the code point to append + * @return this <code>StringBuffer</code> + * @see Character#toChars(int, char[], int) + * @since 1.5 + */ + public synchronized StringBuffer appendCodePoint(int code) + { + int len = Character.charCount(code); + ensureCapacity_unsynchronized(count + len); + Character.toChars(code, value, count); + count += len; + return this; + } + + /** * Append the <code>String</code> value of the argument to this * <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert * to <code>String</code>. @@ -497,21 +481,39 @@ } /** - * Append the code point to this <code>StringBuffer</code>. - * This is like #append(char), but will append two characters - * if a supplementary code point is given. + * Append the characters in the <code>CharSequence</code> to this + * buffer. * - * @param code the code point to append + * @param seq the <code>CharSequence</code> providing the characters * @return this <code>StringBuffer</code> - * @see Character#toChars(int, char[], int) * @since 1.5 */ - public synchronized StringBuffer appendCodePoint(int code) + public synchronized StringBuffer append(CharSequence seq) { - int len = Character.charCount(code); - ensureCapacity_unsynchronized(count + len); - Character.toChars(code, value, count); - count += len; + return append(seq, 0, seq.length()); + } + + /** + * Append some characters from the <code>CharSequence</code> to this + * buffer. If the argument is null, the four characters "null" are + * appended. + * + * @param seq the <code>CharSequence</code> providing the characters + * @param start the starting index + * @param end one past the final index + * @return this <code>StringBuffer</code> + * @since 1.5 + */ + public synchronized StringBuffer append(CharSequence seq, int start, int end) + { + if (seq == null) + return append("null"); + if (end - start > 0) + { + ensureCapacity_unsynchronized(count + end - start); + for (; start < end; ++start) + value[count++] = seq.charAt(start); + } return this; } Modified: trunk/core/src/classpath/java/java/lang/ThreadLocal.java =================================================================== --- trunk/core/src/classpath/java/java/lang/ThreadLocal.java 2007-01-27 10:06:33 UTC (rev 3090) +++ trunk/core/src/classpath/java/java/lang/ThreadLocal.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -84,9 +84,9 @@ * @author Mark Wielaard (ma...@kl...) * @author Eric Blake (eb...@em...) * @since 1.2 - * @status updated to 1.4 + * @status updated to 1.5 */ -public class ThreadLocal +public class ThreadLocal<T> { /** * Placeholder to distinguish between uninitialized and null set by the @@ -125,7 +125,7 @@ * * @return the initial value of the variable in this thread */ - protected Object initialValue() + protected T initialValue() { return null; } @@ -138,7 +138,7 @@ * * @return the value of the variable in this thread */ - public Object get() + public T get() { Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will @@ -149,7 +149,7 @@ value = initialValue(); map.put(key, value == null ? NULL : value); } - return value == NULL ? null : value; + return value == NULL ? null : (T) value; } /** @@ -160,11 +160,22 @@ * * @param value the value to set this thread's view of the variable to */ - public void set(Object value) + public void set(T value) { Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will // ever modify the map. map.put(key, value == null ? NULL : value); } + + /** + * Removes the value associated with the ThreadLocal object for the + * currently executing Thread. + * @since 1.5 + */ + public void remove() + { + Map map = Thread.getThreadLocals(); + map.remove(this); } +} Added: trunk/core/src/classpath/java/java/util/concurrent/locks/ReentrantReadWriteLock.java =================================================================== --- trunk/core/src/classpath/java/java/util/concurrent/locks/ReentrantReadWriteLock.java (rev 0) +++ trunk/core/src/classpath/java/java/util/concurrent/locks/ReentrantReadWriteLock.java 2007-01-27 11:43:17 UTC (rev 3091) @@ -0,0 +1,1346 @@ +/* + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain + */ + +package java.util.concurrent.locks; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; +import java.util.*; + +/** + * An implementation of {@link ReadWriteLock} supporting similar + * semantics to {@link ReentrantLock}. + * <p>This class has the following properties: + * + * <ul> + * <li><b>Acquisition order</b> + * + * <p> This class does not impose a reader or writer preference + * ordering for lock access. However, it does support an optional + * <em>fairness</em> policy. + * + * <dl> + * <dt><b><i>Non-fair mode (default)</i></b> + * <dd>When constructed as non-fair (the default), the order of entry + * to the read and write lock is unspecified, subject to reentrancy + * constraints. A nonfair lock that is continously contended may + * indefinitely postpone one or more reader or writer threads, but + * will normally have higher throughput than a fair lock. + * <p> + * + * <dt><b><i>Fair mode</i></b> + * <dd> When constructed as fair, threads contend for entry using an + * approximately arrival-order policy. When the currently held lock + * is released either the longest-waiting single writer thread will + * be assigned the write lock, or if there is a group of reader threads + * waiting longer than all waiting writer threads, that group will be + * assigned the read lock. + * + * <p>A thread that tries to acquire a fair read lock (non-reentrantly) + * will block if either the write lock is held, or there is a waiting + * writer thread. The thread will not acquire the read lock until + * after the oldest currently waiting writer thread has acquired and + * released the write lock. Of course, if a waiting writer abandons + * its wait, leaving one or more reader threads as the longest waiters + * in the queue with the write lock free, then those readers will be + * assigned the read lock. + * + * <p>A thread that tries to acquire a fair write lock (non-reentrantly) + * will block unless both the read lock and write lock are free (which + * implies there are no waiting threads). (Note that the non-blocking + * {@link ReadLock#tryLock()} and {@link WriteLock#tryLock()} methods + * do not honor this fair setting and will acquire the lock if it is + * possible, regardless of waiting threads.) + * <p> + * </dl> + * + * <li><b>Reentrancy</b> + * + * <p>This lock allows both readers and writers to reacquire read or + * write locks in the style of a {@link ReentrantLock}. Non-reentrant + * readers are not allowed until all write locks held by the writing + * thread have been released. + * + * <p>Additionally, a writer can acquire the read lock, but not + * vice-versa. Among other applications, reentrancy can be useful + * when write locks are held during calls or callbacks to methods that + * perform reads under read locks. If a reader tries to acquire the + * write lock it will never succeed. + * + * <li><b>Lock downgrading</b> + * <p>Reentrancy also allows downgrading from the write lock to a read lock, + * by acquiring the write lock, then the read lock and then releasing the + * write lock. However, upgrading from a read lock to the write lock is + * <b>not</b> possible. + * + * <li><b>Interruption of lock acquisition</b> + * <p>The read lock and write lock both support interruption during lock + * acquisition. + * + * <li><b>{@link Condition} support</b> + * <p>The write lock provides a {@link Condition} implementation that + * behaves in the same way, with respect to the write lock, as the + * {@link Condition} implementation provided by + * {@link ReentrantLock#newCondition} does for {@link ReentrantLock}. + * This {@link Condition} can, of course, only be used with the write lock. + * + * <p>The read lock does not support a {@link Condition} and + * {@code readLock().newCondition()} throws + * {@code UnsupportedOperationException}. + * + * <li><b>Instrumentation</b> + * <p>This class supports methods to determine whether locks + * are held or contended. These methods are designed for monitoring + * system state, not for synchronization control. + * </ul> + * + * <p>Serialization of this class behaves in the same way as built-in + * locks: a deserialized lock is in the unlocked state, regardless of + * its state when serialized. + * + * <p><b>Sample usages</b>. Here is a code sketch showing how to exploit + * reentrancy to perform lock downgrading after updating a cache (exception + * handling is elided for simplicity): + * <pre> + * class CachedData { + * Object data; + * volatile boolean cacheValid; + * ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); + * + * void processCachedData() { + * rwl.readLock().lock(); + * if (!cacheValid) { + * // Must release read lock before acquiring write lock + * rwl.readLock().unlock(); + * rwl.writeLock().lock(); + * // Recheck state because another thread might have acquired + * // write lock and changed state before we did. + * if (!cacheValid) { + * data = ... + * cacheValid = true; + * } + * // Downgrade by acquiring read lock before releasing write lock + * rwl.readLock().lock(); + * rwl.writeLock().unlock(); // Unlock write, still hold read + * } + * + * use(data); + * rwl.readLock().unlock(); + * } + * } + * </pre> + * + * ReentrantReadWriteLocks can be used to improve concurrency in some + * uses of some kinds of Collections. This is typically worthwhile + * only when the collections are expected to be large, accessed by + * more reader threads than writer threads, and entail operations with + * overhead that outweighs synchronization overhead. For example, here + * is a class using a TreeMap that is expected to be large and + * concurrently accessed. + * + * <pre>{@code + * class RWDictionary { + * private final Map<String, Data> m = new TreeMap<String, Data>(); + * private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); + * private final Lock r = rwl.readLock(); + * private final Lock w = rwl.writeLock(); + * + * public Data get(String key) { + * r.lock(); + * try { return m.get(key); } + * finally { r.unlock(); } + * } + * public String[] allKeys() { + * r.lock(); + * try { return m.keySet().toArray(); } + * finally { r.unlock(); } + * } + * public Data put(String key, Data value) { + * w.lock(); + * try { return m.put(key, value); } + * finally { w.unlock(); } + * } + * public void clear() { + * w.lock(); + * try { m.clear(); } + * finally { w.unlock(); } + * } + * }}</pre> + * + * <h3>Implementation Notes</h3> + * + * <p>This lock supports a maximum of 65535 recursive write locks + * and 65535 read locks. Attempts to exceed these limits result in + * {@link Error} throws from locking methods. + * + * @since 1.5 + * @author Doug Lea + * + */ +public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializable { + private static final long serialVersionUID = -6992448646407690164L; + /** Inner class providing readlock */ + private final ReentrantReadWriteLock.ReadLock readerLock; + /** Inner class providing writelock */ + private final ReentrantReadWriteLock.WriteLock writerLock; + /** Performs all synchronization mechanics */ + private final Sync sync; + + /** + * Creates a new {@code ReentrantReadWriteLock} with + * default (nonfair) ordering properties. + */ + public ReentrantReadWriteLock() { + this(false); + } + + /** + * Creates a new {@code ReentrantReadWriteLock} with + * the given fairness policy. + * + * @param fair {@code true} if this lock should use a fair ordering policy + */ + public ReentrantReadWriteLock(boolean fair) { + sync = (fair)? new FairSync() : new NonfairSync(); + readerLock = new ReadLock(this); + writerLock = new WriteLock(this); + } + + public ReentrantReadWriteLock.WriteLock writeLock() { return writerLock; } + public ReentrantReadWriteLock.ReadLock readLock() { return readerLock; } + + /** + * Synchronization implementation for ReentrantReadWriteLock. + * Subclassed into fair and nonfair versions. + */ + static abstract class Sync extends AbstractQueuedSynchronizer { + private static final long serialVersionUID = 6317671515068378041L; + + /* + * Read vs write count extraction constants and functions. + * Lock state is logically divided into two shorts: The lower + * one representing the exclusive (writer) lock hold count, + * and the upper the shared (reader) hold count. + */ + + static final int SHARED_SHIFT = 16; + static final int SHARED_UNIT = (1 << SHARED_SHIFT); + static final int MAX_COUNT = (1 << SHARED_SHIFT) - 1; + static final int EXCLUSIVE_MASK = (1 << SHARED_SHIFT) - 1; + + /** Returns the number of shared holds represented in count */ + static int sharedCount(int c) { return c >>> SHARED_SHIFT; } + /** Returns the number of exclusive holds represented in count */ + static int exclusiveCount(int c) { return c & EXCLUSIVE_MASK; } + + /** + * A counter for per-thread read hold counts. + * Maintained as a ThreadLocal; cached in cachedHoldCounter + */ + static final class HoldCounter { + int count; + // Use id, not reference, to avoid garbage retention + final long tid = Thread.currentThread().getId(); + /** Decrement if positive; return previous value */ + int tryDecrement() { + int c = count; + if (c > 0) + count = c - 1; + return c; + } + } + + /** + * ThreadLocal subclass. Easiest to explicitly define for sake + * of deserialization mechanics. + */ + static final class ThreadLocalHoldCounter + extends ThreadLocal<HoldCounter> { + public HoldCounter initialValue() { + return new HoldCounter(); + } + } + + /** + * The number of read locks held by current thread. + * Initialized only in constructor and readObject. + */ + transient ThreadLocalHoldCounter readHolds; + + /** + * The hold count of the last thread to successfully acquire + * readLock. This saves ThreadLocal lookup in the common case + * where the next thread to release is the last one to + * acquire. This is non-volatile since it is just used + * as a heuristic, and would be great for threads to cache. + */ + transient HoldCounter cachedHoldCounter; + + Sync() { + readHolds = new ThreadLocalHoldCounter(); + setState(getState()); // ensures visibility of readHolds + } + + /* + * Acquires and releases use the same code for fair and + * nonfair locks, but differ in whether/how they allow barging + * when queues are non-empty. + */ + + /** + * Return true if a reader thread that is otherwise + * eligible for lock should block because of policy + * for overtaking other waiting threads. + */ + abstract boolean readerShouldBlock(Thread current); + + /** + * Return true if a writer thread that is otherwise + * eligible for lock should block because of policy + * for overtaking other waiting threads. + */ + abstract boolean writerShouldBlock(Thread current); + + /* + * Note that tryRelease and tryAcquire can be called by + * Conditions. So it is possible that their arguments contain + * both read and write holds that are all released during a + * condition wait and re-established in tryAcquire. + */ + + protected final boolean tryRelease(int releases) { + int nextc = getState() - releases; + if (Thread.currentThread() != getExclusiveOwnerThread()) + throw new IllegalMonitorStateException(); + if (exclusiveCount(nextc) == 0) { + setExclusiveOwnerThread(null); + setState(nextc); + return true; + } else { + setState(nextc); + return false; + } + } + + protected final boolean tryAcquire(int acquires) { + /* + * Walkthrough: + * 1. if read count nonzero or write count nonzero + * and owner is a different thread, fail. + * 2. If count would saturate, fail. (This can only + * happen if count is already nonzero.) + * 3. Otherwise, this thread is eligible for lock if + * it is either a reentrant acquire or + * queue policy allows it. If so, update state + * and set owner. + */ + Thread current = Thread.currentThread(); + int c = getState(); + int w = exclusiveCount(c); + if (c != 0) { + // (Note: if c != 0 and w == 0 then shared count != 0) + if (w == 0 || current != getExclusiveOwnerThread()) + return false; + if (w + exclusiveCount(acquires) > MAX_COUNT) + throw new Error("Maximum lock count exceeded"); + } + if ((w == 0 && writerShouldBlock(current)) || + !compareAndSetState(c, c + acquires)) + return false; + setExclusiveOwnerThread(current); + return true; + } + + protected final boolean tryReleaseShared(int unused) { + HoldCounter rh = cachedHoldCounter; + Thread current = Thread.currentThread(); + if (rh == null || rh.tid != current.getId()) + rh = readHolds.get(); + if (rh.tryDecrement() <= 0) + throw new IllegalMonitorStateException(); + for (;;) { + int c = getState(); + int nextc = c - SHARED_UNIT; + if (compareAndSetState(c, nextc)) + return nextc == 0; + } + } + + protected final int tryAcquireShared(int unused) { + /* + * Walkthrough: + * 1. If write lock held by another thread, fail + * 2. If count saturated, throw error + * 3. Otherwise, this thread is eligible for + * lock wrt state, so ask if it should block + * because of queue policy. If not, try + * to grant by CASing state and updating count. + * Note that step does not check for reentrant + * acquires, which is postponed to full version + * to avoid having to check hold count in + * the more typical non-reentrant case. + * 4. If step 3 fails either because thread + * apparently not eligible or CAS fails, + * chain to version with full retry loop. + */ + Thread current = Thread.currentThread(); + int c = getState(); + if (exclusiveCount(c) != 0 && + getExclusiveOwnerThread() != current) + return -1; + if (sharedCount(c) == MAX_COUNT) + throw new Error("Maximum lock count exceeded"); + if (!readerShouldBlock(current) && + compareAndSetState(c, c + SHARED_UNIT)) { + HoldCounter rh = cachedHoldCounter; + if (rh == null || rh.tid != current.getId()) + cachedHoldCounter = rh = readHolds.get(); + rh.count++; + return 1; + } + return fullTryAcquireShared(current); + } + + /** + * Full version of acquire for reads, that handles CAS misses + * and reentrant reads not dealt with in tryAcquireShared. + */ + final int fullTryAcquireShared(Thread current) { + /* + * This code is in part redundant with that in + * tryAcquireShared but is simpler overall by not + * complicating tryAcquireShared with interactions between + * retries and lazily reading hold counts. + */ + HoldCounter rh = cachedHoldCounter; + if (rh == null || rh.tid != current.getId()) + rh = readHolds.get(); + for (;;) { + int c = getState(); + int w = exclusiveCount(c); + if ((w != 0 && getExclusiveOwnerThread() != current) || + ((rh.count | w) == 0 && readerShouldBlock(current))) + return -1; + if (sharedCount(c) == MAX_COUNT) + throw new Error("Maximum lock count exceeded"); + if (compareAndSetState(c, c + SHARED_UNIT)) { + cachedHoldCounter = rh; // cache for release + rh.count++; + return 1; + } + } + } + + /** + * Performs tryLock for write, enabling barging in both modes. + * This is identical in effect to tryAcquire except for lack + * of calls to writerShouldBlock + */ + final boolean tryWriteLock() { + Thread current = Thread.currentThread(); + int c = getState(); + if (c != 0) { + int w = exclusiveCount(c); + if (w == 0 ||current != getExclusiveOwnerThread()) + return false; + if (w == MAX_COUNT) + throw new Error("Maximum lock count exceeded"); + } + if (!compareAndSetState(c, c + 1)) + return false; + setExclusiveOwnerThread(current); + return true; + } + + /** + * Performs tryLock for read, enabling barging in both modes. + * This is identical in effect to tryAcquireShared except for + * lack of calls to readerShouldBlock + */ + final boolean tryReadLock() { + Thread current = Thread.currentThread(); + for (;;) { + int c = getState(); + if (exclusiveCount(c) != 0 && + getExclusiveOwnerThread() != current) + return false; + if (sharedCount(c) == MAX_COUNT) + throw new Error("Maximum lock count exceeded"); + if (compareAndSetState(c, c + SHARED_UNIT)) { + HoldCounter rh = cachedHoldCounter; + if (rh == null || rh.tid != current.getId()) + cachedHoldCounter = rh = readHolds.get(); + rh.count++; + return true; + } + } + } + + protected final boolean isHeldExclusively() { + // While we must in general read state before owner, + // we don't need to do so to check if current thread is owner + return getExclusiveOwnerThread() == Thread.currentThread(); + } + + // Methods relayed to outer class + + final ConditionObject newCondition() { + return new ConditionObject(); + } + + final Thread getOwner() { + // Must read state before owner to ensure memory consistency + return ((exclusiveCount(getState()) == 0)? + null : + getExclusiveOwnerThread()); + } + + final int getReadLockCount() { + return sharedCount(getState()); + } + + final boolean isWriteLocked() { + return exclusiveCount(getState()) != 0; + } + + final int getWriteHoldCount() { + return isHeldExclusively() ? exclusiveCount(getState()) : 0; + } + + final int getReadHoldCount() { + return getReadLockCount() == 0? 0 : readHolds.get().count; + } + + /** + * Reconstitute this lock instance from a stream + * @param s the stream + */ + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + readHolds = new ThreadLocalHoldCounter(); + setState(0); // reset to unlocked state + } + + final int getCount() { return getState(); } + } + + /** + * Nonfair version of Sync + */ + final static class NonfairSync extends Sync { + private static final long serialVersionUID = -8159625535654395037L; + final boolean writerShouldBlock(Thread current) { + return false; // writers can always barge + } + final boolean readerShouldBlock(Thread current) { + /* As a heuristic to avoid indefinite writer starvation, + * block if the thread that momentarily appears to be head + * of queue, if one exists, is a waiting writer. This is + * only a probablistic effect since a new reader will not + * block if there is a waiting writer behind other enabled + * readers that have not yet drained from the queue. + */ + return apparentlyFirstQueuedIsExclusive(); + } + } + + /** + * Fair version of Sync + */ + final static class FairSync extends Sync { + private static final long serialVersionUID = -2274990926593161451L; + final boolean writerShouldBlock(Thread current) { + // only proceed if queue is empty or current thread at head + return !isFirst(current); + } + final boolean readerShouldBlock(Thread current) { + // only proceed if queue is empty or current thread at head + return !isFirst(current); + } + } + + /** + * The lock returned by method {@link ReentrantReadWriteLock#readLock}. + */ + public static class ReadLock implements Lock, java.io.Serializable { + private static final long serialVersionUID = -5992448646407690164L; + private final Sync sync; + + /** + * Constructor for use by subclasses + * + * @param lock the outer lock object + * @throws NullPointerException i... [truncated message content] |
From: <ls...@us...> - 2007-01-27 10:06:34
|
Revision: 3090 http://jnode.svn.sourceforge.net/jnode/?rev=3090&view=rev Author: lsantha Date: 2007-01-27 02:06:33 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Removed uneeded logging. Modified Paths: -------------- trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java Modified: trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java =================================================================== --- trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java 2007-01-27 10:06:09 UTC (rev 3089) +++ trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java 2007-01-27 10:06:33 UTC (rev 3090) @@ -34,7 +34,6 @@ final SinglePixelPackedSampleModel sppSM = (SinglePixelPackedSampleModel) sampleModel; final int dataType = dataBuffer.getDataType(); final int dataTypeSize = DataBuffer.getDataTypeSize(dataType); - log.debug("dataTypeSize=" + dataTypeSize + ", dataType=" + dataType); this.bitmapGraphics = BitmapGraphics.createInstance(dataBuffer, width, height, sppSM.getScanlineStride() * dataTypeSize / 8, model.getTransparency()); } else { this.bitmapGraphics = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-27 10:06:11
|
Revision: 3089 http://jnode.svn.sourceforge.net/jnode/?rev=3089&view=rev Author: lsantha Date: 2007-01-27 02:06:09 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/image/BufferedImage.java trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java Modified: trunk/core/src/classpath/java/java/awt/image/BufferedImage.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/BufferedImage.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/BufferedImage.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -38,6 +38,7 @@ package java.awt.image; +import gnu.java.awt.Buffers; import gnu.java.awt.ComponentDataBlitOp; import java.awt.Graphics; @@ -129,12 +130,12 @@ * <li>{@link #TYPE_BYTE_INDEXED}</li> * </ul> * - * @param w the width (must be > 0). - * @param h the height (must be > 0). + * @param width the width (must be > 0). + * @param height the height (must be > 0). * @param type the image type (see the list of valid types above). * - * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is - * less than or equal to zero. + * @throws IllegalArgumentException if <code>width</code> or + * <code>height</code> is less than or equal to zero. * @throws IllegalArgumentException if <code>type</code> is not one of the * specified values. */ @@ -161,7 +162,10 @@ width, height, 3, width * 3, new int[]{ 2, 1, 0 } ); - cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 ); + cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + false, false, + BufferedImage.OPAQUE, + DataBuffer.TYPE_BYTE); break; case BufferedImage.TYPE_INT_ARGB: @@ -172,18 +176,25 @@ 0x0000FF00, 0x000000FF, 0xFF000000 } ); + if (premultiplied) + cm = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), + 32, 0xff0000, 0xff00, 0xff, 0xff000000, + true, + Buffers.smallestAppropriateTransferType(32)); + else cm = new DirectColorModel( 32, 0xff0000, 0xff00, 0xff, 0xff000000 ); break; case BufferedImage.TYPE_4BYTE_ABGR: case BufferedImage.TYPE_4BYTE_ABGR_PRE: - sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, + sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, - new int[]{ 0x000000FF, - 0xFF000000, - 0x00FF0000, - 0x0000FF00 } ); - cm = new DirectColorModel( 32, 0xff, 0xff00, 0xff0000, 0xff000000 ); + 4, 4*width, + new int[]{3, 2, 1, 0}); + cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + true, premultiplied, + BufferedImage.TRANSLUCENT, + DataBuffer.TYPE_BYTE); break; case BufferedImage.TYPE_INT_BGR: @@ -192,24 +203,24 @@ new int[]{ 0x000000FF, 0x0000FF00, 0x00FF0000 } ) ; - cm = new DirectColorModel( 32, 0xff, 0xff00, 0xff0000 ); + cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 ); break; case BufferedImage.TYPE_USHORT_565_RGB: sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT, width, height, - new int[]{ 0x0000001F, - 0x000007E0, - 0x0000F800 } ) ; - cm = new DirectColorModel( 16, 0x1F, 0x7E0, 0xf800 ); + new int[]{ 0xF800, + 0x7E0, + 0x1F } ) ; + cm = new DirectColorModel( 16, 0xF800, 0x7E0, 0x1F ); break; case BufferedImage.TYPE_USHORT_555_RGB: sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT, width, height, - new int[]{ 0x0000001F, - 0x000003E0, - 0x00007C00 } ) ; - cm = new DirectColorModel( 15, 0x1F, 0x3E0, 0x7c00 ); + new int[]{ 0x7C00, + 0x3E0, + 0x1F } ) ; + cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F ); break; case BufferedImage.TYPE_BYTE_INDEXED: @@ -287,7 +298,7 @@ public BufferedImage(ColorModel colormodel, WritableRaster writableraster, boolean premultiplied, - Hashtable properties) + Hashtable<?,?> properties) { init(colormodel, writableraster, premultiplied, properties, TYPE_CUSTOM); @@ -347,6 +358,7 @@ public void coerceData(boolean premultiplied) { colorModel = colorModel.coerceData(raster, premultiplied); + isPremultiplied = premultiplied; } public WritableRaster copyData(WritableRaster dest) @@ -616,7 +628,7 @@ }; } - public Vector getSources() + public Vector<RenderedImage> getSources() { return null; } Modified: trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -306,16 +306,15 @@ public ColorModel coerceData(WritableRaster raster, boolean isAlphaPremultiplied) { - if (this.isAlphaPremultiplied == isAlphaPremultiplied) + if (this.isAlphaPremultiplied == isAlphaPremultiplied || !hasAlpha()) return this; /* TODO: provide better implementation based on the assumptions we can make due to the specific type of the color model. */ - super.coerceData(raster, isAlphaPremultiplied); + super.coerceDataWorker(raster, isAlphaPremultiplied); - return new ComponentColorModel(cspace, bits, hasAlpha(), - isAlphaPremultiplied, // argument + return new ComponentColorModel(cspace, hasAlpha, isAlphaPremultiplied, transparency, transferType); } Modified: trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -91,11 +91,12 @@ * * @param props the list of properties associated with this image */ - public void setProperties(Hashtable props) + public void setProperties(Hashtable<?, ?> props) { - props.put("filters", "CropImageFilter"); + Hashtable<Object, Object> prop2 = (Hashtable<Object, Object>) props; + prop2.put("filters", "CropImageFilter"); if (consumer != null) - consumer.setProperties(props); + consumer.setProperties(prop2); } /** Modified: trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -393,20 +393,20 @@ return Buffers.getData(buffer); } - public final ColorModel coerceData (WritableRaster raster, + public ColorModel coerceData (WritableRaster raster, boolean isAlphaPremultiplied) { - if (this.isAlphaPremultiplied == isAlphaPremultiplied) + if (this.isAlphaPremultiplied == isAlphaPremultiplied || !hasAlpha()) return this; /* TODO: provide better implementation based on the assumptions we can make due to the specific type of the color model. */ - super.coerceData(raster, isAlphaPremultiplied); + super.coerceDataWorker(raster, isAlphaPremultiplied); - return new ComponentColorModel(cspace, bits, hasAlpha(), - isAlphaPremultiplied, // argument - transparency, transferType); + return new DirectColorModel(cspace, pixel_bits, getRedMask(), + getGreenMask(), getBlueMask(), getAlphaMask(), + isAlphaPremultiplied, transferType); } public boolean isCompatibleRaster(Raster raster) Modified: trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -134,11 +134,7 @@ if (size < 1) throw new IllegalArgumentException("size < 1"); map_size = size; - if (0 <= trans && trans < size) { - this.trans = trans; - transparency = BITMASK; - } - rgb = new int[size]; + rgb = createColorMap(bits, size); for (int i = 0; i < size; i++) { rgb[i] = (0xff000000 @@ -146,6 +142,9 @@ | ((greens[i] & 0xff) << 8) | (blues[i] & 0xff)); } + + setTransparentPixel(trans); + // Generate a bigint with 1's for every pixel validBits = validBits.setBit(size).subtract(BigInteger.ONE); } @@ -188,7 +187,7 @@ map_size = size; opaque = (alphas == null); - rgb = new int[size]; + rgb = createColorMap(bits, size); if (alphas == null) { for (int i = 0; i < size; i++) @@ -275,10 +274,8 @@ throw new IllegalArgumentException("size < 1"); map_size = size; opaque = !hasAlpha; - if (0 <= trans && trans < size) - this.trans = trans; - rgb = new int[size]; + rgb = createColorMap(bits, size); if (hasAlpha) { int alpha; @@ -318,6 +315,8 @@ transparency = BITMASK; } + setTransparentPixel(trans); + // Generate a bigint with 1's for every pixel validBits = validBits.setBit(size).subtract(BigInteger.ONE); } @@ -361,16 +360,15 @@ throw new IllegalArgumentException("size < 1"); map_size = size; opaque = !hasAlpha; - if (0 <= trans && trans < size) - this.trans = trans; - - rgb = new int[size]; + rgb = createColorMap(bits, size); if (!hasAlpha) for (int i = 0; i < size; i++) rgb[i] = cmap[i + start] | 0xff000000; else System.arraycopy(cmap, start, rgb, 0, size); + setTransparentPixel(trans); + // Generate a bigint with 1's for every pixel validBits = validBits.setBit(size).subtract(BigInteger.ONE); } @@ -421,7 +419,7 @@ this.trans = -1; this.validBits = validBits; - rgb = new int[size]; + rgb = createColorMap(bits, size); if (!hasAlpha) for (int i = 0; i < size; i++) rgb[i] = cmap[i + start] | 0xff000000; @@ -584,12 +582,7 @@ */ public final int getAlpha(int pixel) { - if (opaque && pixel != trans) - return 255; - if ((pixel == trans && trans != -1) || pixel >= map_size) - return 0; - - return (0xFF000000 & rgb[pixel]) >> 24; + return (rgb[pixel] >> 24) & 0xFF; } /** @@ -694,4 +687,50 @@ return im; } + + /** + * Creates a {@link SampleModel} that is compatible to this color model. + * This will be a {@link MultiPixelPackedSampleModel} for bits/pixel of + * 1, 2 or 4, or a {@link ComponentColorModel} for the other cases. + * + * @param w the width of the sample model to create + * @param h the height of the sample model to create + * + * @return a compatible sample model + */ + public SampleModel createCompatibleSampleModel(int w, int h) + { + SampleModel sm; + if (pixel_bits == 1 || pixel_bits == 2 || pixel_bits == 4) + sm = new MultiPixelPackedSampleModel(transferType, w, h, pixel_bits); + else + sm = new ComponentSampleModel(transferType, w, h, 1, w, new int[]{0}); + return sm; + } + + /** + * Sets the transparent pixel. This is called by the various constructors. + * + * @param t the transparent pixel + */ + private void setTransparentPixel(int t) + { + if (t >= 0 && t < map_size) + { + rgb[t] &= 0xffffff; // Make the value transparent. + trans = t; + if (transparency == OPAQUE) + { + transparency = BITMASK; + hasAlpha = true; + } + } + } + + private int[] createColorMap(int bits, int size) + { + // According to a Mauve test, the RI allocates at least 256 entries here. + int realSize = Math.max(256, Math.max(1 << bits, size)); + return new int[realSize]; + } } Modified: trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java 2007-01-27 09:39:31 UTC (rev 3088) +++ trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java 2007-01-27 10:06:09 UTC (rev 3089) @@ -1,5 +1,5 @@ /* MemoryImageSource.java -- Java class for providing image data - Copyright (C) 1999, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2004, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,6 +41,9 @@ import java.util.Hashtable; import java.util.Vector; +/** + * An image producer that delivers image data from an array. + */ public class MemoryImageSource implements ImageProducer { private boolean animated = false; @@ -73,10 +76,19 @@ } /** - * Constructs an ImageProducer from memory + * Constructs an ImageProducer from memory. + * + * @param w the image width. + * @param h the image height. + * @param cm the color model. + * @param pix the image data. + * @param off the offset to the first pixel in the array. + * @param scan the number of array elements from a pixel on one row to the + * corresponding pixel on the next row. + * @param props image properties (<code>null</code> permitted). */ public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, - int scan, Hashtable props) + int scan, Hashtable<?,?> props) { width = w; height = h; @@ -106,10 +118,19 @@ } /** - Constructs an ImageProducer from memory + * Constructs an ImageProducer from memory + * + * @param w the image width. + * @param h the image height. + * @param cm the color model. + * @param pix the image data. + * @param off the offset to the first pixel in the array. + * @param scan the number of array elements from a pixel on one row to the + * corresponding pixel on the next row. + * @param props image properties (<code>null</code> permitted). */ public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, - int scan, Hashtable props) + int scan, Hashtable<?,?> props) { width = w; height = h; @@ -122,16 +143,32 @@ } /** - * Constructs an ImageProducer from memory using the default RGB ColorModel + * Constructs an ImageProducer from memory using the default RGB ColorModel. + * + * @param w the image width. + * @param h the image height. + * @param pix the image data. + * @param off the offset to the first pixel in the array. + * @param scan the number of array elements from a pixel on one row to the + * corresponding pixel on the next row. + * @param props image properties (<code>null</code> permitted). + */ public MemoryImageSource(int w, int h, int[] pix, int off, int scan, - Hashtable props) + Hashtable<?,?> props) { this(w, h, ColorModel.getRGBdefault(), pix, off, scan, props); } /** - * Constructs an ImageProducer from memory using the default RGB ColorModel + * Constructs an ImageProducer from memory using the default RGB ColorModel. + * + * @param w the image width. + * @param h the image height. + * @param pix the image data. + * @param off the offset to the first pixel in the array. + * @param scan the number of array elements from a pixel on one row to the + * corresponding pixel on the next row. */ public MemoryImageSource(int w, int h, int[] pix, int off, int scan) { @@ -141,6 +178,8 @@ /** * Used to register an <code>ImageConsumer</code> with this * <code>ImageProducer</code>. + * + * @param ic the image consumer. */ public synchronized void addConsumer(ImageConsumer ic) { @@ -153,6 +192,8 @@ /** * Used to determine if the given <code>ImageConsumer</code> is * already registered with this <code>ImageProducer</code>. + * + * @param ic the image consumer. */ public synchronized boolean isConsumer(ImageConsumer ic) { @@ -164,6 +205,8 @@ /** * Used to remove an <code>ImageConsumer</code> from the list of * registered consumers for this <code>ImageProducer</code>. + * + * @param ic the image consumer. */ public synchronized void removeConsumer(ImageConsumer ic) { @@ -197,6 +240,8 @@ * Used to register an <code>ImageConsumer</code> with this * <code>ImageProducer</code> and then request that this producer * resend the image data in the order top-down, left-right. + * + * @param ic the image consumer. */ public void requestTopDownLeftRightResend(ImageConsumer ic) { @@ -219,7 +264,7 @@ * sending animation. If this flag is set then full buffers are sent * in the newPixels methods instead of just regions. * - * @param fullbuffers - a flag indicating whether to send the full buffers + * @param fullbuffers a flag indicating whether to send the full buffers */ public synchronized void setFullBufferUpdates(boolean fullbuffers) { @@ -260,6 +305,11 @@ /** * Send an animation frame to the image consumers containing the specified * pixels unless setFullBufferUpdates is set. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param w the width. + * @param h the height. */ public synchronized void newPixels(int x, int y, int w, int h) { @@ -306,6 +356,12 @@ * * If framenotify is set then a notification is sent when the frame * is sent otherwise no status is sent. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param w the width. + * @param h the height. + * @param framenotify send notification? */ public synchronized void newPixels(int x, int y, int w, int h, boolean framenotify) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-27 09:39:36
|
Revision: 3088 http://jnode.svn.sourceforge.net/jnode/?rev=3088&view=rev Author: lsantha Date: 2007-01-27 01:39:31 -0800 (Sat, 27 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/java/awt/peer/GLightweightPeer.java trunk/core/src/classpath/java/java/awt/CheckboxMenuItem.java trunk/core/src/classpath/java/java/awt/MenuItem.java trunk/core/src/classpath/java/java/awt/image/AffineTransformOp.java trunk/core/src/classpath/java/java/awt/image/BandCombineOp.java trunk/core/src/classpath/java/java/awt/image/ColorConvertOp.java trunk/core/src/classpath/java/java/awt/image/ColorModel.java trunk/core/src/classpath/java/java/awt/image/ConvolveOp.java trunk/core/src/classpath/java/java/awt/image/ImageConsumer.java trunk/core/src/classpath/java/java/awt/image/ImageFilter.java trunk/core/src/classpath/java/java/awt/image/LookupOp.java trunk/core/src/classpath/java/java/awt/image/PixelGrabber.java trunk/core/src/classpath/java/java/awt/image/RGBImageFilter.java trunk/core/src/classpath/java/java/awt/image/Raster.java trunk/core/src/classpath/java/java/awt/image/RenderedImage.java trunk/core/src/classpath/java/java/awt/image/ReplicateScaleFilter.java trunk/core/src/classpath/java/java/awt/image/RescaleOp.java trunk/core/src/classpath/java/java/awt/image/SampleModel.java trunk/core/src/classpath/java/java/awt/image/SinglePixelPackedSampleModel.java trunk/core/src/classpath/java/java/awt/image/WritableRaster.java trunk/core/src/classpath/java/java/text/DateFormat.java trunk/core/src/classpath/java/java/text/DateFormatSymbols.java trunk/core/src/classpath/java/java/text/DecimalFormatSymbols.java trunk/core/src/classpath/java/java/text/NumberFormat.java trunk/core/src/classpath/java/java/util/Arrays.java trunk/core/src/classpath/javax/javax/swing/ToolTipManager.java trunk/core/src/classpath/javax/javax/swing/TransferHandler.java trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/JarVerifier.java trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Main.java trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Messages.java trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/SFHelper.java trunk/core/src/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/java/awt/ComponentReshapeEvent.java trunk/core/src/classpath/gnu/gnu/java/awt/dnd/ trunk/core/src/classpath/gnu/gnu/java/awt/dnd/GtkMouseDragGestureRecognizer.java trunk/core/src/classpath/java/java/text/spi/DateFormatProvider.java trunk/core/src/classpath/java/java/text/spi/DecimalFormatSymbolsProvider.java trunk/core/src/classpath/java/java/text/spi/NumberFormatProvider.java trunk/core/src/classpath/javax/javax/management/AttributeChangeNotification.java Added: trunk/core/src/classpath/gnu/gnu/java/awt/ComponentReshapeEvent.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/ComponentReshapeEvent.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/java/awt/ComponentReshapeEvent.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -0,0 +1,85 @@ +/* WindowResizeEvent.java -- Used to synchronize the AWT and peer sizes + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.awt; + +import java.awt.AWTEvent; +import java.awt.Component; + +/** + * This is used to update the AWT's knowledge about a Window's size when + * the user changes the window bounds. + * + * This event is _not_ posted to the eventqueue, but rather dispatched directly + * via Window.dispatchEvent(). It is the cleanest way we could find to update + * the AWT's knowledge of the window size. Small testprograms showed the + * following: + * - Component.reshape() and its derivatives are _not_ called. This makes sense + * as it could end up in loops,because this calls back into the peers. + * - Intercepting event dispatching for any events in + * EventQueue.dispatchEvent() showed that the size is still updated. So it + * is not done via an event dispatched over the eventqueue. + * + * Possible other candidates for implementation would have been: + * - Call a (private) callback method in Window/Component from the native + * side. + * - Call a (private) callback method in Window/Component via reflection. + * + * Both is uglier than sending this event directly. Note however that this + * is impossible to test, as Component.dispatchEvent() is final and can't be + * intercepted from outside code. But this impossibility to test the issue from + * outside code also means that this shouldn't raise any compatibility issues. + */ +public class ComponentReshapeEvent + extends AWTEvent +{ + + public int x; + public int y; + public int width; + public int height; + + public ComponentReshapeEvent(Component c, int x, int y, int width, int height) + { + super(c, 1999); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} Added: trunk/core/src/classpath/gnu/gnu/java/awt/dnd/GtkMouseDragGestureRecognizer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/dnd/GtkMouseDragGestureRecognizer.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/java/awt/dnd/GtkMouseDragGestureRecognizer.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -0,0 +1,172 @@ +/* GtkMouseDragGestureRecognizer.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.awt.dnd; + +import java.awt.Component; +import java.awt.Point; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragSource; +import java.awt.dnd.MouseDragGestureRecognizer; +import java.awt.event.MouseEvent; + +public class GtkMouseDragGestureRecognizer + extends MouseDragGestureRecognizer +{ + + public GtkMouseDragGestureRecognizer (DragSource ds) + { + this(ds, null, 0, null); + } + + public GtkMouseDragGestureRecognizer (DragSource ds, Component c) + { + this (ds, c, 0, null); + } + + public GtkMouseDragGestureRecognizer (DragSource ds, Component c, int act) + { + this(ds, c, act, null); + } + + public GtkMouseDragGestureRecognizer (DragSource ds, Component c, int act, + DragGestureListener dgl) + { + super(ds, c, act, dgl); + } + + public void registerListeners () + { + super.registerListeners(); + } + + public void unregisterListeners () + { + super.unregisterListeners(); + } + + public void mouseClicked (MouseEvent e) + { + // Nothing to do here. + } + + public void mousePressed (MouseEvent e) + { + events.clear(); + if (getDropActionFromEvent(e) != DnDConstants.ACTION_NONE) + appendEvent(e); + } + + public void mouseReleased (MouseEvent e) + { + events.clear(); + } + + public void mouseEntered (MouseEvent e) + { + events.clear(); + } + + public void mouseExited(MouseEvent e) + { + if (!events.isEmpty()) + if (getDropActionFromEvent(e) == DnDConstants.ACTION_NONE) + events.clear(); + } + + public void mouseDragged(MouseEvent e) + { + if (!events.isEmpty()) + { + int act = getDropActionFromEvent(e); + + if (act == DnDConstants.ACTION_NONE) + return; + + Point origin = ((MouseEvent) events.get(0)).getPoint(); + Point current = e.getPoint(); + int dx = Math.abs(origin.x - current.x); + int dy = Math.abs(origin.y - current.y); + int threshold = DragSource.getDragThreshold(); + + if (dx > threshold || dy > threshold) + fireDragGestureRecognized(act, origin); + else + appendEvent(e); + } + } + + public void mouseMoved (MouseEvent e) + { + // Nothing to do here. + } + + private int getDropActionFromEvent(MouseEvent e) + { + int modEx = e.getModifiersEx(); + int buttons = modEx & (MouseEvent.BUTTON1_DOWN_MASK + | MouseEvent.BUTTON2_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK); + if (!(buttons == MouseEvent.BUTTON1_DOWN_MASK || + buttons == MouseEvent.BUTTON2_DOWN_MASK)) + return DnDConstants.ACTION_NONE; + + // Convert modifier to a drop action + int sourceActions = getSourceActions(); + int mod = modEx + & (MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK); + switch (mod) + { + case MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK: + return DnDConstants.ACTION_LINK & sourceActions; + case MouseEvent.CTRL_DOWN_MASK: + return DnDConstants.ACTION_COPY & sourceActions; + case MouseEvent.SHIFT_DOWN_MASK: + return DnDConstants.ACTION_MOVE & sourceActions; + default: + if ((sourceActions & DnDConstants.ACTION_MOVE) != 0) + return DnDConstants.ACTION_MOVE & sourceActions; + else if ((sourceActions & DnDConstants.ACTION_COPY) != 0) + return DnDConstants.ACTION_COPY & sourceActions; + else if ((sourceActions & DnDConstants.ACTION_LINK) != 0) + return DnDConstants.ACTION_LINK & sourceActions; + } + + return DnDConstants.ACTION_NONE & sourceActions; + } +} Modified: trunk/core/src/classpath/gnu/gnu/java/awt/peer/GLightweightPeer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/peer/GLightweightPeer.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/gnu/gnu/java/awt/peer/GLightweightPeer.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -163,8 +163,10 @@ public FontMetrics getFontMetrics(Font f) { - // Nothing to do here for lightweights. - return null; + // We shouldn't end up here, but if we do we can still try do something + // reasonable. + Toolkit tk = Toolkit.getDefaultToolkit(); + return tk.getFontMetrics(f); } /* Returning null here tells the Component object that called us to @@ -201,7 +203,31 @@ public void handleEvent(AWTEvent e) { - // Nothing to do here for lightweights. + // This can only happen when an application posts a PaintEvent for + // a lightweight component directly. We still support painting for + // this case. + if (e instanceof PaintEvent) + { + PaintEvent pe = (PaintEvent) e; + Component target = (Component) e.getSource(); + if (target != null && target.isShowing()) + { + Graphics g = target.getGraphics(); + if (g != null) + { + try + { + Rectangle clip = pe.getUpdateRect(); + g.setClip(clip); + target.paint(g); + } + finally + { + g.dispose(); + } + } + } + } } public void hide() Modified: trunk/core/src/classpath/java/java/awt/CheckboxMenuItem.java =================================================================== --- trunk/core/src/classpath/java/java/awt/CheckboxMenuItem.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/CheckboxMenuItem.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -318,7 +318,7 @@ * @exception ClassCastException If listenerType doesn't specify a class or * interface that implements java.util.EventListener. */ - public EventListener[] getListeners (Class listenerType) + public <T extends EventListener> T[] getListeners (Class<T> listenerType) { if (listenerType == ItemListener.class) return AWTEventMulticaster.getListeners (item_listeners, listenerType); Modified: trunk/core/src/classpath/java/java/awt/MenuItem.java =================================================================== --- trunk/core/src/classpath/java/java/awt/MenuItem.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/MenuItem.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -523,11 +523,11 @@ * ClassClassException is thrown. * @since 1.3 */ - public EventListener[] getListeners(Class listenerType) + public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (listenerType == ActionListener.class) - return getActionListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); + return (T[]) getActionListeners(); + return (T[]) Array.newInstance(listenerType, 0); } /*************************************************************************/ Modified: trunk/core/src/classpath/java/java/awt/image/AffineTransformOp.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/AffineTransformOp.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/AffineTransformOp.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -39,6 +39,7 @@ package java.awt.image; import java.awt.Graphics2D; +import java.awt.Point; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; @@ -48,8 +49,11 @@ import java.util.Arrays; /** - * This class performs affine transformation between two images or - * rasters in 2 dimensions. + * AffineTransformOp performs matrix-based transformations (translations, + * scales, flips, rotations, and shears). + * + * If interpolation is required, nearest neighbour, bilinear, and bicubic + * methods are available. * * @author Olga Rodimina (rod...@re...) * @author Francis Kung (fk...@re...) @@ -115,14 +119,14 @@ } /** - * Creates empty BufferedImage with the size equal to that of the - * transformed image and correct number of bands. The newly created + * Creates a new BufferedImage with the size equal to that of the + * transformed image and the correct number of bands. The newly created * image is created with the specified ColorModel. - * If the ColorModel is equal to null, an appropriate ColorModel is used. + * If a ColorModel is not specified, an appropriate ColorModel is used. * - * @param src source image - * @param destCM color model for the destination image - * @return new compatible destination image + * @param src the source image. + * @param destCM color model for the destination image (can be null). + * @return a new compatible destination image. */ public BufferedImage createCompatibleDestImage (BufferedImage src, ColorModel destCM) @@ -145,21 +149,18 @@ } /** - * Creates empty WritableRaster with the size equal to the transformed - * source raster and correct number of bands + * Creates a new WritableRaster with the size equal to the transformed + * source raster and correct number of bands . * - * @param src source raster - * @throws RasterFormatException if resulting width or height of raster is 0 - * @return new compatible raster + * @param src the source raster. + * @throws RasterFormatException if resulting width or height of raster is 0. + * @return a new compatible raster. */ public WritableRaster createCompatibleDestRaster (Raster src) { Rectangle2D rect = getBounds2D(src); - // throw RasterFormatException if resulting width or height of the - // transformed raster is 0 - - if (rect.getWidth () == 0 || rect.getHeight () == 0) + if (rect.getWidth() == 0 || rect.getHeight() == 0) throw new RasterFormatException("width or height is 0"); return src.createCompatibleWritableRaster((int) rect.getWidth(), @@ -175,24 +176,22 @@ * @param dst destination image * @throws IllegalArgumentException if the source and destination image are * the same - * @return transformed source image + * @return transformed source image. */ public final BufferedImage filter (BufferedImage src, BufferedImage dst) { - if (dst == src) - throw new IllegalArgumentException ("src image cannot be the same as " + - "the dst image"); + throw new IllegalArgumentException("src image cannot be the same as " + + "the dst image"); // If the destination image is null, then use a compatible BufferedImage if (dst == null) dst = createCompatibleDestImage(src, null); - Graphics2D gr = (Graphics2D) dst.createGraphics (); - gr.setRenderingHints (hints); - gr.drawImage (src, transform, null); + Graphics2D gr = (Graphics2D) dst.createGraphics(); + gr.setRenderingHints(hints); + gr.drawImage(src, transform, null); return dst; - } /** @@ -204,10 +203,11 @@ * @param dst destination raster * @throws IllegalArgumentException if the source and destination are not * compatible - * @return transformed raster + * @return transformed raster. */ - public final WritableRaster filter (Raster src, WritableRaster dst) + public final WritableRaster filter(Raster src, WritableRaster dst) { + // Initial checks if (dst == src) throw new IllegalArgumentException("src image cannot be the same as" + " the dst image"); @@ -219,6 +219,24 @@ throw new IllegalArgumentException("src and dst must have same number" + " of bands"); + // Optimization for rasters that can be represented in the RGB colormodel: + // wrap the rasters in images, and let Cairo do the transformation + if (ColorModel.getRGBdefault().isCompatibleSampleModel(src.getSampleModel()) + && ColorModel.getRGBdefault().isCompatibleSampleModel(dst.getSampleModel())) + { + WritableRaster src2 = Raster.createWritableRaster(src.getSampleModel(), + src.getDataBuffer(), + new Point(src.getMinX(), + src.getMinY())); + BufferedImage iSrc = new BufferedImage(ColorModel.getRGBdefault(), + src2, false, null); + BufferedImage iDst = new BufferedImage(ColorModel.getRGBdefault(), dst, + false, null); + + return filter(iSrc, iDst).getRaster(); + } + + // Otherwise, we need to do the transformation in java code... // Create arrays to hold all the points double[] dstPts = new double[dst.getHeight() * dst.getWidth() * 2]; double[] srcPts = new double[dst.getHeight() * dst.getWidth() * 2]; @@ -287,7 +305,7 @@ } /** - * Returns interpolation type used during transformations + * Returns interpolation type used during transformations. * * @return interpolation type */ @@ -319,7 +337,7 @@ /** * Returns rendering hints that are used during transformation. * - * @return rendering hints + * @return the rendering hints used in this Op. */ public final RenderingHints getRenderingHints () { @@ -330,7 +348,7 @@ * Returns transform used in transformation between source and destination * image. * - * @return transform + * @return the transform used in this Op. */ public final AffineTransform getTransform () { @@ -377,6 +395,18 @@ { Rectangle srcbounds = src.getBounds(); + Object xyarr = null; + Object xp1arr = null; + Object yp1arr = null; + Object xyp1arr = null; + + double xy; + double xp1; + double yp1; + double xyp1; + + double[] result = new double[src.getNumBands()]; + // For all points in the destination raster, use bilinear interpolation // to find the value from the corrosponding source points for (int i = 0; i < dpts.length; i += 2) @@ -401,21 +431,64 @@ double xdiff = pts[i] + src.getMinX() - x; double ydiff = pts[i + 1] + src.getMinY() - y; - // Run the interpolation for each band + // Get surrounding pixels used in interpolation... optimized + // to use the smallest datatype possible. + if (src.getTransferType() == DataBuffer.TYPE_DOUBLE + || src.getTransferType() == DataBuffer.TYPE_FLOAT) + { + xyarr = src.getPixel(x, y, (double[])xyarr); + xp1arr = src.getPixel(x+1, y, (double[])xp1arr); + yp1arr = src.getPixel(x, y+1, (double[])yp1arr); + xyp1arr = src.getPixel(x+1, y+1, (double[])xyp1arr); + } + else + { + xyarr = src.getPixel(x, y, (int[])xyarr); + xp1arr = src.getPixel(x+1, y, (int[])xp1arr); + yp1arr = src.getPixel(x, y+1, (int[])yp1arr); + xyp1arr = src.getPixel(x+1, y+1, (int[])xyp1arr); + } + // using + // array[] pixels = src.getPixels(x, y, 2, 2, pixels); + // instead of doing four individual src.getPixel() calls + // should be faster, but benchmarking shows that it's not... + + // Run interpolation for each band for (int j = 0; j < src.getNumBands(); j++) { - double result = (src.getSampleDouble(x, y, j) * (1 - xdiff) - + src.getSampleDouble(x + 1, y, j) * xdiff) - * (1 - ydiff) - + (src.getSampleDouble(x, y + 1, j) - * (1 - xdiff) - + src.getSampleDouble(x + 1, y + 1, j) - * xdiff) + // Pull individual sample values out of array + if (src.getTransferType() == DataBuffer.TYPE_DOUBLE + || src.getTransferType() == DataBuffer.TYPE_FLOAT) + { + xy = ((double[])xyarr)[j]; + xp1 = ((double[])xp1arr)[j]; + yp1 = ((double[])yp1arr)[j]; + xyp1 = ((double[])xyp1arr)[j]; + } + else + { + xy = ((int[])xyarr)[j]; + xp1 = ((int[])xp1arr)[j]; + yp1 = ((int[])yp1arr)[j]; + xyp1 = ((int[])xyp1arr)[j]; + } + + // If all four samples are identical, there's no need to + // calculate anything + if (xy == xp1 && xy == yp1 && xy == xyp1) + result[j] = xy; + + // Run bilinear interpolation formula + else + result[j] = (xy * (1-xdiff) + xp1 * xdiff) + * (1-ydiff) + + (yp1 * (1-xdiff) + xyp1 * xdiff) * ydiff; - dst.setSample((int) dpts[i] + dst.getMinX(), - (int) dpts[i + 1] + dst.getMinY(), - j, result); } + + dst.setPixel((int)dpts[i] + dst.getMinX(), + (int)dpts[i+1] + dst.getMinY(), + result); } } } @@ -434,10 +507,11 @@ double[] pts) { Rectangle srcbounds = src.getBounds(); + double[] result = new double[src.getNumBands()]; + Object pixels = null; // For all points on the destination raster, perform bicubic interpolation // from corrosponding source points - double[] result = new double[src.getNumBands()]; for (int i = 0; i < dpts.length; i += 2) { if (srcbounds.contains((int) Math.round(pts[i]) + src.getMinX(), @@ -450,7 +524,6 @@ Arrays.fill(result, 0); for (int m = - 1; m < 3; m++) - { for (int n = - 1; n < 3; n++) { // R(x) = ( P(x+2)^3 - 4 P(x+1)^3 + 6 P(x)^3 - 4 P(x-1)^3 ) / 6 @@ -459,7 +532,6 @@ // Calculate R(m - dx) double rx = m - dx + 2; - if (rx > 0) r1 += rx * rx * rx; rx = m - dx + 1; @@ -509,17 +581,27 @@ else if (srcY < src.getMinY()) srcY = src.getMinY(); - // Calculate once for each band + // Calculate once for each band, using the smallest + // datatype possible + if (src.getTransferType() == DataBuffer.TYPE_DOUBLE + || src.getTransferType() == DataBuffer.TYPE_FLOAT) + { + pixels = src.getPixel(srcX, srcY, (double[])pixels); for (int j = 0; j < result.length; j++) - result[j] += src.getSample(srcX, srcY, j) * r1 * r2; + result[j] += ((double[])pixels)[j] * r1 * r2; + } + else + { + pixels = src.getPixel(srcX, srcY, (int[])pixels); + for (int j = 0; j < result.length; j++) + result[j] += ((int[])pixels)[j] * r1 * r2; } } // Put it all together - for (int j = 0; j < result.length; j++) - dst.setSample((int) dpts[i] + dst.getMinX(), - (int) dpts[i + 1] + dst.getMinY(), - j, result[j]); + dst.setPixel((int)dpts[i] + dst.getMinX(), + (int)dpts[i+1] + dst.getMinY(), + result); } } } Modified: trunk/core/src/classpath/java/java/awt/image/BandCombineOp.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/BandCombineOp.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/BandCombineOp.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -40,6 +40,7 @@ import java.awt.RenderingHints; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.Arrays; /** * Filter Raster pixels by applying a matrix. @@ -53,6 +54,9 @@ * for the destination. Therefore the destination Raster must contain the * same number of bands as the number of rows in the filter matrix. * + * This Op assumes that samples are integers; floating point sample types will + * be rounded to their nearest integer value during filtering. + * * @author Jerry Quinn (jl...@op...) */ public class BandCombineOp implements RasterOp @@ -109,19 +113,27 @@ throw new IllegalArgumentException("Destination raster is incompatible with source raster"); // Filter the pixels - float[] spix = new float[matrix[0].length - 1]; - float[] dpix = new float[matrix.length]; + int[] spix = new int[matrix[0].length - 1]; + int[] spix2 = new int[matrix[0].length - 1]; + int[] dpix = new int[matrix.length]; for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) { // In case matrix rows have implicit translation - spix[spix.length - 1] = 1.0f; + spix[spix.length - 1] = 1; src.getPixel(x, y, spix); + + // Do not re-calculate if pixel is identical to the last one + // (ie, blocks of the same colour) + if (!Arrays.equals(spix, spix2)) + { + System.arraycopy(spix, 0, spix2, 0, spix.length); for (int i = 0; i < matrix.length; i++) { dpix[i] = 0; for (int j = 0; j < matrix[0].length - 1; j++) - dpix[i] += spix[j] * matrix[i][j]; + dpix[i] += spix[j] * (int)matrix[i][j]; + } } dest.setPixel(x, y, dpix); } Modified: trunk/core/src/classpath/java/java/awt/image/ColorConvertOp.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ColorConvertOp.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/ColorConvertOp.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -38,6 +38,8 @@ package java.awt.image; +import gnu.java.awt.Buffers; + import java.awt.Graphics2D; import java.awt.Point; import java.awt.RenderingHints; @@ -283,7 +285,8 @@ for (int i = 0; i < spaces.length - 2; i++) { WritableRaster tmp = createCompatibleDestRaster(src, spaces[i + 1], - false); + false, + src.getTransferType()); copyraster(src, spaces[i], tmp, spaces[i + 1]); src = tmp; } @@ -291,7 +294,8 @@ // The last conversion is done outside of the loop so that we can // use the dest raster supplied, instead of creating our own temp raster if (dest == null) - dest = createCompatibleDestRaster(src, spaces[spaces.length - 1], false); + dest = createCompatibleDestRaster(src, spaces[spaces.length - 1], false, + DataBuffer.TYPE_BYTE); copyraster(src, spaces[spaces.length - 2], dest, spaces[spaces.length - 1]); return dest; @@ -324,7 +328,8 @@ return new BufferedImage(dstCM, createCompatibleDestRaster(src.getRaster(), dstCM.getColorSpace(), - src.getColorModel().hasAlpha), + src.getColorModel().hasAlpha, + dstCM.getTransferType()), src.isPremultiplied, null); } @@ -349,7 +354,8 @@ // Create a new raster with the last ColorSpace in the conversion // chain, and with no alpha (implied) - return createCompatibleDestRaster(src, spaces[spaces.length-1], false); + return createCompatibleDestRaster(src, spaces[spaces.length-1], false, + DataBuffer.TYPE_BYTE); } /** @@ -417,11 +423,16 @@ return src.getBounds(); } - // Copy a source image to a destination image, respecting their colorspaces - // and performing colorspace conversions if necessary. This is done - // using Graphics2D in order to use the rendering hints. + /** + * Copy a source image to a destination image, respecting their colorspaces + * and performing colorspace conversions if necessary. + * + * @param src The source image. + * @param dst The destination image. + */ private void copyimage(BufferedImage src, BufferedImage dst) { + // This is done using Graphics2D in order to respect the rendering hints. Graphics2D gg = dst.createGraphics(); // If no hints are set there is no need to call @@ -433,8 +444,16 @@ gg.dispose(); } - // Copy a source raster to a destination raster, performing a colorspace - // conversion. + /** + * Copy a source raster to a destination raster, performing a colorspace + * conversion between the two. The conversion will respect the + * KEY_COLOR_RENDERING rendering hint if one is present. + * + * @param src The source raster. + * @param scs The colorspace of the source raster. + * @dst The destination raster. + * @dcs The colorspace of the destination raster. + */ private void copyraster(Raster src, ColorSpace scs, WritableRaster dst, ColorSpace dcs) { float[] sbuf = new float[src.getNumBands()]; @@ -459,11 +478,19 @@ } } - // This method creates a compatible color model, given a source image and - // a colorspace. The choice of ComponentColorModel and DataBuffer.TYPE_BYTE - // is based on Mauve testing of the reference implementation. + /** + * This method creates a color model with the same colorspace and alpha + * settings as the source image. The created color model will always be a + * ComponentColorModel and have a BYTE transfer type. + * + * @param img The source image. + * @param cs The ColorSpace to use. + * @return A color model compatible with the source image. + */ private ColorModel createCompatibleColorModel(BufferedImage img, ColorSpace cs) { + // The choice of ComponentColorModel and DataBuffer.TYPE_BYTE is based on + // Mauve testing of the reference implementation. return new ComponentColorModel(cs, img.getColorModel().hasAlpha(), img.isAlphaPremultiplied(), @@ -471,13 +498,22 @@ DataBuffer.TYPE_BYTE); } - // This method creates a compatible Raster, given a source raster and - // colorspace. - private WritableRaster createCompatibleDestRaster(Raster src, ColorSpace cs, boolean hasAlpha) + /** + * This method creates a compatible Raster, given a source raster, colorspace, + * alpha value, and transfer type. + * + * @param src The source raster. + * @param cs The ColorSpace to use. + * @param hasAlpha Whether the raster should include a component for an alpha. + * @param transferType The size of a single data element. + * @return A compatible WritableRaster. + */ + private WritableRaster createCompatibleDestRaster(Raster src, ColorSpace cs, + boolean hasAlpha, + int transferType) { - // The use of a PixelInterleavedSampleModel (and it's parameters) and - // a DataBufferByte were determined using mauve tests, based on the - // reference implementation + // The use of a PixelInterleavedSampleModel weas determined using mauve + // tests, based on the reference implementation int numComponents = cs.getNumComponents(); if (hasAlpha) @@ -487,13 +523,15 @@ for (int i = 0; i < offsets.length; i++) offsets[i] = i; - return new WritableRaster(new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, + DataBuffer db = Buffers.createBuffer(transferType, + src.getWidth() * src.getHeight() * numComponents, + 1); + return new WritableRaster(new PixelInterleavedSampleModel(transferType, src.getWidth(), src.getHeight(), numComponents, numComponents * src.getWidth(), offsets), - new DataBufferByte(src.getWidth() * src.getHeight() * numComponents, 1), - new Point(src.getMinX(), src.getMinY())); + db, new Point(src.getMinX(), src.getMinY())); } } Modified: trunk/core/src/classpath/java/java/awt/image/ColorModel.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ColorModel.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/ColorModel.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -119,12 +119,8 @@ */ public ColorModel(int bits) { - // @classpath-bugfix Fix difference between Sun's class and this class. - //this(bits * 4, // total bits, sRGB, four channels - this(bits, // total bits, sRGB, four channels - //nArray(bits, 4), // bits for each channel - nArray(bits / 4, 4), // bits for each channel - // @classpath-bugfix-end + this(bits * 4, // total bits, sRGB, four channels + nArray(bits, 4), // bits for each channel ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB true, // has alpha false, // not premultiplied @@ -628,40 +624,40 @@ return cspace; } - // Typically overridden public ColorModel coerceData(WritableRaster raster, boolean isAlphaPremultiplied) { - if (this.isAlphaPremultiplied == isAlphaPremultiplied || ! hasAlpha) - return this; + // This method should always be overridden, but is not abstract. + throw new UnsupportedOperationException(); + } + protected void coerceDataWorker(WritableRaster raster, + boolean isAlphaPremultiplied) + { int w = raster.getWidth(); int h = raster.getHeight(); int x = raster.getMinX(); int y = raster.getMinY(); - int size = w*h; + int size = w * h; int numColors = getNumColorComponents(); int numComponents = getNumComponents(); - int alphaScale = (1<<getComponentSize(numColors)) - 1; + int alphaScale = (1 << getComponentSize(numColors)) - 1; double[] pixels = raster.getPixels(x, y, w, h, (double[]) null); - for (int i=0; i<size; i++) + for (int i = 0; i < size; i++) { - double alpha = pixels[i*numComponents+numColors]*alphaScale; - for (int c=0; c<numColors; c++) + double alpha = pixels[i * numComponents + numColors] / alphaScale; + for (int c = 0; c < numColors; c++) { - int offset = i*numComponents+c; + int offset = i * numComponents + c; if (isAlphaPremultiplied) - pixels[offset] = pixels[offset]/alpha; + pixels[offset] = Math.round(pixels[offset] * alpha); else - pixels[offset] = pixels[offset]*alpha; + pixels[offset] = Math.round(pixels[offset] / alpha); } } raster.setPixels(0, 0, w, h, pixels); - - // FIXME: what can we return? - return null; } /** Modified: trunk/core/src/classpath/java/java/awt/image/ConvolveOp.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ConvolveOp.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/ConvolveOp.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -38,7 +38,6 @@ package java.awt.image; -import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -51,11 +50,13 @@ * with elements in the kernel to compute a new pixel. * * Each band in a Raster is convolved and copied to the destination Raster. + * For BufferedImages, convolution is applied to all components. Color + * conversion will be applied if needed. * - * For BufferedImages, convolution is applied to all components. If the - * source is not premultiplied, the data will be premultiplied before - * convolving. Premultiplication will be undone if the destination is not - * premultiplied. Color conversion will be applied if needed. + * Note that this filter ignores whether the source or destination is alpha + * premultiplied. The reference spec states that data will be premultiplied + * prior to convolving and divided back out afterwards (if needed), but testing + * has shown that this is not the case with their implementation. * * @author jl...@op... */ @@ -104,59 +105,83 @@ hints = null; } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, - * java.awt.image.BufferedImage) + /** + * Converts the source image using the kernel specified in the + * constructor. The resulting image is stored in the destination image if one + * is provided; otherwise a new BufferedImage is created and returned. + * + * The source and destination BufferedImage (if one is supplied) must have + * the same dimensions. + * + * @param src The source image. + * @param dst The destination image. + * @throws IllegalArgumentException if the rasters and/or color spaces are + * incompatible. + * @return The convolved image. */ public final BufferedImage filter(BufferedImage src, BufferedImage dst) { if (src == dst) - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Source and destination images " + + "cannot be the same."); if (dst == null) dst = createCompatibleDestImage(src, src.getColorModel()); // Make sure source image is premultiplied BufferedImage src1 = src; - if (!src.isPremultiplied) + // The spec says we should do this, but mauve testing shows that Sun's + // implementation does not check this. + /* + if (!src.isAlphaPremultiplied()) { src1 = createCompatibleDestImage(src, src.getColorModel()); src.copyData(src1.getRaster()); src1.coerceData(true); } + */ BufferedImage dst1 = dst; - if (!src.getColorModel().equals(dst.getColorModel())) + if (src1.getColorModel().getColorSpace().getType() != dst.getColorModel().getColorSpace().getType()) dst1 = createCompatibleDestImage(src, src.getColorModel()); filter(src1.getRaster(), dst1.getRaster()); + // Since we don't coerceData above, we don't need to divide it back out. + // This is wrong (one mauve test specifically tests converting a non- + // premultiplied image to a premultiplied image, and it shows that Sun + // simply ignores the premultipled flag, contrary to the spec), but we + // mimic it for compatibility. + /* + if (! dst.isAlphaPremultiplied()) + dst1.coerceData(false); + */ + + // Convert between color models if needed if (dst1 != dst) - { - // Convert between color models. - // TODO Check that premultiplied alpha is handled correctly here. - Graphics2D gg = dst.createGraphics(); - gg.setRenderingHints(hints); - gg.drawImage(dst1, 0, 0, null); - gg.dispose(); - } + new ColorConvertOp(hints).filter(dst1, dst); return dst; } - /* (non-Javadoc) - * @see - * java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, - * java.awt.image.ColorModel) + /** + * Creates an empty BufferedImage with the size equal to the source and the + * correct number of bands. The new image is created with the specified + * ColorModel, or if no ColorModel is supplied, an appropriate one is chosen. + * + * @param src The source image. + * @param dstCM A color model for the destination image (may be null). + * @return The new compatible destination image. */ public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) { - // FIXME: set properties to those in src + if (dstCM != null) return new BufferedImage(dstCM, src.getRaster().createCompatibleWritableRaster(), - src.isPremultiplied, null); + src.isAlphaPremultiplied(), null); + + return new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); } /* (non-Javadoc) @@ -168,6 +193,8 @@ } /** + * Get the edge condition for this Op. + * * @return The edge condition. */ public int getEdgeCondition() @@ -185,9 +212,22 @@ return (Kernel) kernel.clone(); } - /* (non-Javadoc) - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, - * java.awt.image.WritableRaster) + /** + * Converts the source raster using the kernel specified in the constructor. + * The resulting raster is stored in the destination raster if one is + * provided; otherwise a new WritableRaster is created and returned. + * + * If the convolved value for a sample is outside the range of [0-255], it + * will be clipped. + * + * The source and destination raster (if one is supplied) cannot be the same, + * and must also have the same dimensions. + * + * @param src The source raster. + * @param dest The destination raster. + * @throws IllegalArgumentException if the rasters identical. + * @throws ImagingOpException if the convolution is not possible. + * @return The transformed raster. */ public final WritableRaster filter(Raster src, WritableRaster dest) { @@ -209,6 +249,11 @@ int top = kernel.getYOrigin(); int bottom = Math.max(kHeight - top - 1, 0); + // Calculate max sample values for clipping + int[] maxValue = src.getSampleModel().getSampleSize(); + for (int i = 0; i < maxValue.length; i++) + maxValue[i] = (int)Math.pow(2, maxValue[i]) - 1; + // process the region that is reachable... int regionW = src.width - left - right; int regionH = src.height - top - bottom; @@ -229,6 +274,13 @@ // FIXME: in the above line, I've had to reverse the order of // the samples array to make the tests pass. I haven't worked // out why this is necessary. + + // This clipping is is undocumented, but determined by testing. + if (v > maxValue[b]) + v = maxValue[b]; + else if (v < 0) + v = 0; + dest.setSample(x + kernel.getXOrigin(), y + kernel.getYOrigin(), b, v); } @@ -310,13 +362,14 @@ return src.getBounds(); } - /** Return corresponding destination point for source point. + /** + * Returns the corresponding destination point for a source point. Because + * this is not a geometric operation, the destination and source points will + * be identical. * - * ConvolveOp will return the value of src unchanged. * @param src The source point. - * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, - * java.awt.geom.Point2D) + * @param dst The transformed destination point. + * @return The transformed destination point. */ public final Point2D getPoint2D(Point2D src, Point2D dst) { Modified: trunk/core/src/classpath/java/java/awt/image/ImageConsumer.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ImageConsumer.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/ImageConsumer.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -136,7 +136,7 @@ * * @param props the list of properties associated with this image */ - void setProperties(Hashtable props); + void setProperties(Hashtable<?,?> props); /** * This <code>ColorModel</code> should indicate the model used by Modified: trunk/core/src/classpath/java/java/awt/image/ImageFilter.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/ImageFilter.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/ImageFilter.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -104,12 +104,8 @@ */ public ImageFilter getFilterInstance(ImageConsumer ic) { - if ( ic == null ) - throw new IllegalArgumentException("null argument for ImageFilter.getFilterInstance(ImageConsumer)"); - - consumer = ic; ImageFilter f = (ImageFilter)clone(); - consumer = null; + f.consumer = ic; return f; } @@ -125,7 +121,6 @@ */ public void setDimensions(int width, int height) { - if (consumer != null) consumer.setDimensions(width, height); } @@ -135,11 +130,16 @@ * * @param props the list of properties associated with this image */ - public void setProperties(Hashtable props) + public void setProperties(Hashtable<?,?> props) { - props.put("filters", "ImageFilter"); - if (consumer != null) - consumer.setProperties(props); + Hashtable copy = (Hashtable) props.clone(); + Object o = copy.get("filters"); + if (o == null) + copy.put("filters", toString()); + else if (o instanceof String) + copy.put("filters", ((String) o) + toString()); + + consumer.setProperties(copy); } /** @@ -148,10 +148,11 @@ * method of the consumer is called with the specified <code>model</code>. * * @param model the color model to be used most often by setPixels - * @see ColorModel */ + * + * @see ColorModel + */ public void setColorModel(ColorModel model) { - if (consumer != null) consumer.setColorModel(model); } @@ -167,7 +168,6 @@ */ public void setHints(int flags) { - if (consumer != null) consumer.setHints(flags); } @@ -186,9 +186,9 @@ * @param scansize the width to use in extracting pixels from the <code>pixels</code> array */ public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize) + ColorModel model, byte[] pixels, int offset, + int scansize) { - if (consumer != null) consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); } @@ -207,9 +207,9 @@ * @param scansize the width to use in extracting pixels from the <code>pixels</code> array */ public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize) + ColorModel model, int[] pixels, int offset, + int scansize) { - if (consumer != null) consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); } @@ -221,8 +221,6 @@ */ public void imageComplete(int status) { - if (consumer != null) consumer.imageComplete(status); } } - Modified: trunk/core/src/classpath/java/java/awt/image/LookupOp.java =================================================================== --- trunk/core/src/classpath/java/java/awt/image/LookupOp.java 2007-01-27 07:54:10 UTC (rev 3087) +++ trunk/core/src/classpath/java/java/awt/image/LookupOp.java 2007-01-27 09:39:31 UTC (rev 3088) @@ -38,7 +38,6 @@ package java.awt.image; -import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -67,7 +66,8 @@ private LookupTable lut; private RenderingHints hints; - /** Construct a new LookupOp. + /** + * Construct a new LookupOp using the given LookupTable. * * @param lookup LookupTable to use. * @param hints Rendering hints (can be null). @@ -78,16 +78,40 @@ this.hints = hints; } - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage) + /** + * Converts the source image using the lookup table specified in the + * constructor. The resulting image is stored in the destination image if one + * is provided; otherwise a new BufferedImage is created and returned. + * + * The source image cannot use an IndexColorModel, and the destination image + * (if one is provided) must have the same size. + * + * @param src The source image. + * @param dst The destination image. + * @throws IllegalArgumentException if the rasters and/or color spaces are + * incompatible. + * @throws ArrayIndexOutOfBoundsException if a pixel in the source is not + * contained in the LookupTable. + * @return The convolved image. */ public final BufferedImage filter(BufferedImage src, BufferedImage dst) { if (src.getColorModel() instanceof IndexColorModel) throw new IllegalArgumentException("LookupOp.filter: IndexColorModel " + "not allowed"); + + if (lut.getNumComponents() != 1 + && lut.getNumComponents() != src.getColorModel().getNumComponents() + && lut.getNumComponents() != src.getColorModel().getNumColorComponents()) + throw new IllegalArgumentException("LookupOp.filter: Incompatible " + + "lookup table and source image"); + if (dst == null) - dst = createCompatibleDestImage(src, src.getColorModel()); + dst = createCompatibleDestImage(src, null); + + else if (src.getHeight() != dst.getHeight() || src.getWidth() != dst.getWidth()) + throw new IllegalArgumentException("Source and destination images are " + + "different sizes."); // Set up for potential colormodel mismatch BufferedImage tgt; @@ -116,15 +140,23 @@ sr.getPixel(x, y, dbuf); System.arraycopy(dbuf, 0, tmp, 0, tmpBands); dr.setPixel(x, y, lut.lookupPixel(tmp, dbuf)); + + /* The reference implementation does not use LookupTable.lookupPixel, + * but rather it seems to copy the table into a native array. The + * effect of this (a probable bug in their implementation) is that + * an out-of-bounds lookup on a ByteLookupTable will *not* throw an + * out of bounds exception, but will instead return random garbage. + * A bad lookup on a ShortLookupTable, however, will throw an + * exception. + * + * Instead of mimicing this behaviour, we always throw an + * ArrayOutofBoundsException by virtue of using + * LookupTable.lookupPixle. + */ } } - else if (lut.getNumComponents() != 1 - && - lut.getNumComponents() != src.getColorModel().getNumComponents()) - throw new IllegalArgumentException("LookupOp.filter: " - + "Incompatible lookup " - + "table and source image"); - + else + { // No alpha to ignore int[] dbuf = new int[src.getColorModel().getNumComponents()]; @@ -132,16 +164,10 @@ for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) dr.setPixel(x, y, lut.lookupPixel(sr.getPixel(x, y, dbuf), dbuf)); + } if (tgt != dst) - { - // Convert between color models. - // TODO Check that premultiplied alpha is handled correctly here. - Graphics2D gg = dst.createGraphics(); - gg.setRenderingHints(hints); - gg.drawImage(tgt, 0, 0, null); - gg.dispose(); - } + new ColorConvertOp(hints).filter(tgt, dst); return dst; } @@ -160,18 +186,27 @@ public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) { - // FIXME: set properties to those in src + if (dstCM != null) return new BufferedImage(dstCM, src.getRaster().createCompatibleWritableRaster(), - src.isPremultiplied, null); + src.isAlphaPremultiplied(), null); + + // This is a strange exception, done for compatibility with the reference + // (as demonstrated by a mauve testcase) + int imgType = src.getType(); + if (imgType == BufferedImage.TYPE_USHORT_GRAY) + imgType = BufferedImage.TYPE_BYTE_GRAY; + + return new BufferedImage(src.getWidth(), src.getHeight(), imgType); } - /** Return corresponding destination point for source point. + /** + * Returns the corresponding destination point for a given source point. * - * LookupOp will return the value of src unchanged. + * This Op will return the source point unchanged. + * * @param src The source point. * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D) */ public final Point2D getPoint2D(Point2D src, Point2D dst) { @@ -182,7 +217,11 @@ return dst; } - /** Return the LookupTable for this op. */ + /** + * Return the LookupTable for this op. + * + * @return The lookup table. + */ public final LookupTable getTable() { return lut; @@ -196,7 +235,8 @@ return hints; } - /** Filter a raster through a lookup table. + /** + * Filter a raster through a lookup table. * * Applies the lookup table for this Rasterop to each pixel of src and * puts the results in dest. If dest is null, a new Raster is created and @@ -207,7 +247,8 @@ * @return The WritableRaster with the filtered pixels. * @throws IllegalArgumentException if lookup ta... [truncated message content] |
From: <ls...@us...> - 2007-01-27 07:54:11
|
Revision: 3087 http://jnode.svn.sourceforge.net/jnode/?rev=3087&view=rev Author: lsantha Date: 2007-01-26 23:54:10 -0800 (Fri, 26 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/lang/reflect/AccessibleObject.java trunk/core/src/classpath/java/java/lang/reflect/Proxy.java trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java trunk/core/src/classpath/vm/java/lang/reflect/Field.java trunk/core/src/classpath/vm/java/lang/reflect/Method.java Modified: trunk/core/src/classpath/java/java/lang/reflect/AccessibleObject.java =================================================================== --- trunk/core/src/classpath/java/java/lang/reflect/AccessibleObject.java 2007-01-20 08:55:33 UTC (rev 3086) +++ trunk/core/src/classpath/java/java/lang/reflect/AccessibleObject.java 2007-01-27 07:54:10 UTC (rev 3087) @@ -1,5 +1,5 @@ /* java.lang.reflect.AccessibleObject - Copyright (C) 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,8 @@ package java.lang.reflect; +import java.lang.annotation.Annotation; + /** * This class is the superclass of various reflection classes, and * allows sufficiently trusted code to bypass normal restrictions to @@ -53,9 +55,10 @@ * @see Method * @see ReflectPermission * @since 1.2 - * @status updated to 1.4 + * @status updated to 1.5 */ public class AccessibleObject + implements AnnotatedElement { /** * True if this object is marked accessible, which means the reflected @@ -156,4 +159,24 @@ throw new SecurityException("Cannot make object accessible: " + this); this.flag = flag; } + + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) + { + throw new AssertionError("Subclass must override this method"); + } + + public Annotation[] getAnnotations() + { + return getDeclaredAnnotations(); + } + + public Annotation[] getDeclaredAnnotations() + { + throw new AssertionError("Subclass must override this method"); + } + + public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) + { + return getAnnotation(annotationClass) != null; + } } Modified: trunk/core/src/classpath/java/java/lang/reflect/Proxy.java =================================================================== --- trunk/core/src/classpath/java/java/lang/reflect/Proxy.java 2007-01-20 08:55:33 UTC (rev 3086) +++ trunk/core/src/classpath/java/java/lang/reflect/Proxy.java 2007-01-27 07:54:10 UTC (rev 3087) @@ -158,7 +158,7 @@ * @see Class * @author Eric Blake (eb...@em...) * @since 1.3 - * @status updated to 1.4, except for the use of ProtectionDomain + * @status updated to 1.5, except for the use of ProtectionDomain */ public class Proxy implements Serializable { @@ -257,8 +257,8 @@ */ // synchronized so that we aren't trying to build the same class // simultaneously in two threads - public static synchronized Class getProxyClass(ClassLoader loader, - Class[] interfaces) + public static synchronized Class<?> getProxyClass(ClassLoader loader, + Class<?>... interfaces) { interfaces = (Class[]) interfaces.clone(); ProxyType pt = new ProxyType(loader, interfaces); @@ -312,7 +312,7 @@ * @see Constructor#newInstance(Object[]) */ public static Object newProxyInstance(ClassLoader loader, - Class[] interfaces, + Class<?>[] interfaces, InvocationHandler handler) { try @@ -360,7 +360,7 @@ */ // This is synchronized on the off chance that another thread is // trying to add a class to the map at the same time we read it. - public static synchronized boolean isProxyClass(Class clazz) + public static synchronized boolean isProxyClass(Class<?> clazz) { if (! Proxy.class.isAssignableFrom(clazz)) return false; @@ -889,7 +889,7 @@ // constant_pool[], filled in as we go // access_flags - putU2(/*Modifier.SUPER |*/ Modifier.FINAL | Modifier.PUBLIC); + putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC); // this_class qualName = (data.pack + "$Proxy" + data.id); putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false))); Modified: trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java 2007-01-20 08:55:33 UTC (rev 3086) +++ trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java 2007-01-27 07:54:10 UTC (rev 3087) @@ -38,6 +38,7 @@ package java.lang.reflect; +import gnu.java.lang.ClassHelper; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -46,6 +47,8 @@ import org.jnode.vm.classmgr.VmMethod; import gnu.java.lang.reflect.MethodSignatureParser; +import java.util.Arrays; + /** * The Constructor class represents a constructor of a class. It also allows * dynamic creation of an object, via reflection. Invocation on Constructor @@ -104,7 +107,8 @@ * Gets the class that declared this constructor. * @return the class that declared this member */ - public Class<T> getDeclaringClass() { + public Class<T> getDeclaringClass() + { return (Class<T>) vmMethod.getDeclaringClass().asClass(); } @@ -123,12 +127,11 @@ * this will include the synthetic and varargs bits. * @return the constructor's modifiers */ - private int getModifiersInternal() { + private int getModifiersInternal() + { return vmMethod.getModifiers(); } - - /** * Gets the modifiers this constructor uses. Use the <code>Modifier</code> * class to interpret the values. A constructor can only have a subset of the @@ -169,7 +172,8 @@ * * @return a list of the types of the constructor's parameters */ - public Class<?>[] getParameterTypes() { + public Class<?>[] getParameterTypes() + { if (parameterTypes == null) { int cnt = vmMethod.getNoArguments(); ArrayList<Class> list = new ArrayList<Class>(cnt); @@ -211,8 +215,16 @@ * @param o the object to compare to * @return <code>true</code> if they are equal; <code>false</code> if not. */ - public boolean equals(Object o) { - return (this == o); + public boolean equals(Object o) + { + if (!(o instanceof Constructor)) + return false; + Constructor that = (Constructor)o; + if (this.getDeclaringClass() != that.getDeclaringClass()) + return false; + if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes())) + return false; + return true; } /** @@ -240,23 +252,60 @@ // 128 is a reasonable buffer initial size for constructor StringBuilder sb = new StringBuilder(128); Modifier.toString(getModifiers(), sb).append(' '); - final Class<?> declClass = getDeclaringClass(); - sb.append(declClass.getName()).append('('); - Class<?>[] c = getParameterTypes(); - if (c.length > 0) { - sb.append(c[0].getName()); - for (int i = 1; i < c.length; i++) { - sb.append(',').append(c[i].getName()); + sb.append(getDeclaringClass().getName()).append('('); + Class[] c = getParameterTypes(); + if (c.length > 0) + { + sb.append(ClassHelper.getUserName(c[0])); + for (int i = 1; i < c.length; i++) + sb.append(',').append(ClassHelper.getUserName(c[i])); } - } sb.append(')'); c = getExceptionTypes(); if (c.length > 0) { sb.append(" throws ").append(c[0].getName()); - for (int i = 1; i < c.length; i++) { + for (int i = 1; i < c.length; i++) sb.append(',').append(c[i].getName()); } + return sb.toString(); } + + static <X extends GenericDeclaration> + void addTypeParameters(StringBuilder sb, TypeVariable<X>[] typeArgs) + { + if (typeArgs.length == 0) + return; + sb.append('<'); + for (int i = 0; i < typeArgs.length; ++i) + { + if (i > 0) + sb.append(','); + sb.append(typeArgs[i]); + } + sb.append("> "); + } + + public String toGenericString() + { + StringBuilder sb = new StringBuilder(128); + Modifier.toString(getModifiers(), sb).append(' '); + addTypeParameters(sb, getTypeParameters()); + sb.append(getDeclaringClass().getName()).append('('); + Type[] types = getGenericParameterTypes(); + if (types.length > 0) + { + sb.append(types[0]); + for (int i = 1; i < types.length; ++i) + sb.append(',').append(types[i]); + } + sb.append(')'); + types = getGenericExceptionTypes(); + if (types.length > 0) + { + sb.append(" throws ").append(types[0]); + for (int i = 1; i < types.length; i++) + sb.append(',').append(types[i]); + } return sb.toString(); } @@ -294,14 +343,6 @@ return (T) VmReflection.newInstance(vmMethod, args); } - /** - * Return the String in the Signature attribute for this constructor. If there - * is no Signature attribute, return null. - */ - private String getSignature(){ - //todo implement it - return null; - } /** * Returns an array of <code>TypeVariable</code> objects that represents @@ -315,7 +356,7 @@ * specification, version 3. * @since 1.5 */ - public TypeVariable[] getTypeParameters() + public TypeVariable<Constructor<T>>[] getTypeParameters() { String sig = getSignature(); if (sig == null) @@ -325,6 +366,15 @@ } /** + * Return the String in the Signature attribute for this constructor. If there + * is no Signature attribute, return null. + */ + private String getSignature() + { + return vmMethod.getSignature(); + } + + /** * Returns an array of <code>Type</code> objects that represents * the exception types declared by this constructor, in declaration order. * An array of size zero is returned if this constructor declares no Modified: trunk/core/src/classpath/vm/java/lang/reflect/Field.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/reflect/Field.java 2007-01-20 08:55:33 UTC (rev 3086) +++ trunk/core/src/classpath/vm/java/lang/reflect/Field.java 2007-01-27 07:54:10 UTC (rev 3087) @@ -1,56 +1,71 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - +/* java.lang.reflect.Field - reflection of Java fields + Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + package java.lang.reflect; -import java.lang.annotation.Annotation; +import gnu.java.lang.ClassHelper; +import gnu.java.lang.reflect.FieldSignatureParser; import org.jnode.vm.VmReflection; import org.jnode.vm.classmgr.VmField; +import java.lang.annotation.Annotation; /** * The Field class represents a member variable of a class. It also allows - * dynamic access to a member, via reflection. This works for both static and - * instance fields. Operations on Field objects know how to do widening - * conversions, but throw {@link IllegalArgumentException}if a narrowing - * conversion would be necessary. You can query for information on this Field - * regardless of location, but get and set access may be limited by Java - * language access controls. If you can't do it in the compiler, you can't - * normally do it here either. - * <p> + * dynamic access to a member, via reflection. This works for both + * static and instance fields. Operations on Field objects know how to + * do widening conversions, but throw {@link IllegalArgumentException} if + * a narrowing conversion would be necessary. You can query for information + * on this Field regardless of location, but get and set access may be limited + * by Java language access controls. If you can't do it in the compiler, you + * can't normally do it here either.<p> * - * <B>Note: </B> This class returns and accepts types as Classes, even primitive - * types; there are Class types defined that represent each different primitive - * type. They are <code>java.lang.Boolean.TYPE, - * java.lang.Byte.TYPE,</code>, - * also available as <code>boolean.class, - * byte.class</code>, etc. These are - * not to be confused with the classes - * <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are real - * classes. - * <p> + * <B>Note:</B> This class returns and accepts types as Classes, even + * primitive types; there are Class types defined that represent each + * different primitive type. They are <code>java.lang.Boolean.TYPE, + * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class, + * byte.class</code>, etc. These are not to be confused with the + * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are + * real classes.<p> * - * Also note that this is not a serializable class. It is entirely feasible to - * make it serializable using the Externalizable interface, but this is on Sun, - * not me. + * Also note that this is not a serializable class. It is entirely feasible + * to make it serializable using the Externalizable interface, but this is + * on Sun, not me. * * @author John Keiser * @author Eric Blake <eb...@em...> @@ -63,8 +78,9 @@ * @since 1.1 * @status updated to 1.4 */ -public final class Field extends AccessibleObject implements Member, AnnotatedElement { - +public final class Field +extends AccessibleObject implements Member +{ private final VmField vmField; private static final int FIELD_MODIFIERS @@ -80,13 +96,13 @@ } /** - * Gets the class that declared this field, or the class where this field is - * a non-inherited member. - * + * Gets the class that declared this field, or the class where this field + * is a non-inherited member. * @return the class that declared this member */ - public Class getDeclaringClass() { - return vmField.getDeclaringClass().asClass(); + public Class<?> getDeclaringClass() + { + return vmField.getDeclaringClass().asClass(); } /** @@ -99,13 +115,8 @@ } /** - * Gets the modifiers this field uses. Use the <code>Modifier</code> class - * to interpret the values. A field can only have a subset of the following - * modifiers: public, private, protected, static, final, transient, and - * volatile. - * - * @return an integer representing the modifiers to this Member - * @see Modifier + * Return the raw modifiers for this field. + * @return the field's modifiers */ public int getModifiersInternal() { return vmField.getModifiers(); @@ -154,68 +165,82 @@ } /** - * Compare two objects to see if they are semantically equivalent. Two - * Fields are semantically equivalent if they have the same declaring class, - * name, and type. Since you can't creat a Field except through the VM, this - * is just the == relation. + * Compare two objects to see if they are semantically equivalent. + * Two Fields are semantically equivalent if they have the same declaring + * class, name, and type. Since you can't creat a Field except through + * the VM, this is just the == relation. * - * @param o - * the object to compare to - * @return <code>true</code> if they are equal; <code>false</code> if - * not + * @param o the object to compare to + * @return <code>true</code> if they are equal; <code>false</code> if not */ - public boolean equals(Object o) { - return this == o; + public boolean equals(Object o) + { + if (!(o instanceof Field)) + return false; + Field that = (Field)o; + if (this.getDeclaringClass() != that.getDeclaringClass()) + return false; + if (!this.getName().equals(that.getName())) + return false; + if (this.getType() != that.getType()) + return false; + return true; } /** - * Get the hash code for the Field. The Field hash code is the hash code of - * its name XOR'd with the hash code of its class name. + * Get the hash code for the Field. The Field hash code is the hash code + * of its name XOR'd with the hash code of its class name. * * @return the hash code for the object. */ - public int hashCode() { - final Class<?> declClass = getDeclaringClass(); - return declClass.getName().hashCode() ^ getName().hashCode(); + public int hashCode() + { + return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); } /** - * Get a String representation of the Field. A Field's String representation - * is "<modifiers> <type> <class>.<fieldname>". <br> - * Example: + * Get a String representation of the Field. A Field's String + * representation is "<modifiers> <type> + * <class>.<fieldname>".<br> Example: * <code>public transient boolean gnu.parse.Parser.parseComplete</code> * * @return the String representation of the Field */ public String toString() { // 64 is a reasonable buffer initial size for field - StringBuffer sb = new StringBuffer(64); + StringBuilder sb = new StringBuilder(64); Modifier.toString(getModifiers(), sb).append(' '); - final Class<?> type = getType(); - final Class<?> declClass = getDeclaringClass(); - sb.append(type.getName()).append(' '); - sb.append(declClass.getName()).append('.'); + sb.append(ClassHelper.getUserName(getType())).append(' '); + sb.append(getDeclaringClass().getName()).append('.'); sb.append(getName()); return sb.toString(); } + public String toGenericString() + { + StringBuilder sb = new StringBuilder(64); + Modifier.toString(getModifiers(), sb).append(' '); + sb.append(getGenericType()).append(' '); + sb.append(getDeclaringClass().getName()).append('.'); + sb.append(getName()); + return sb.toString(); + } + /** - * Get the value of this Field. If it is primitive, it will be wrapped in - * the appropriate wrapper type (boolean = java.lang.Boolean). - * <p> + * Get the value of this Field. If it is primitive, it will be wrapped + * in the appropriate wrapper type (boolean = java.lang.Boolean).<p> * * If the field is static, <code>o</code> will be ignored. Otherwise, if * <code>o</code> is null, you get a <code>NullPointerException</code>, - * and if it is incompatible with the declaring class of the field, you get - * an <code>IllegalArgumentException</code>. - * <p> + * and if it is incompatible with the declaring class of the field, you + * get an <code>IllegalArgumentException</code>.<p> * * Next, if this Field enforces access control, your runtime context is * evaluated, and you may have an <code>IllegalAccessException</code> if - * you could not access this field in similar compiled code. If the field is - * static, and its class is uninitialized, you trigger class initialization, - * which may end in a <code>ExceptionInInitializerError</code>. - * <p> + * you could not access this field in similar compiled code. If the field + * is static, and its class is uninitialized, you trigger class + * initialization, which may end in a + * <code>ExceptionInInitializerError</code>.<p> * * Finally, the field is accessed, and primitives are wrapped (but not * necessarily in new objects). This method accesses the field of the @@ -333,22 +358,17 @@ * Get the value of this Field as a short. If the field is static, * <code>o</code> will be ignored. * - * @param o - * the object to get the value of this Field from + * @param o the object to get the value of this Field from * @return the value of the Field - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte or short field of <code>o</code>, or - * if <code>o</code> is not an instance of the declaring class - * of this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte or short + * field of <code>o</code>, or if <code>o</code> is not an instance + * of the declaring class of this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #get(Object) */ public short getShort(Object o) throws IllegalAccessException { @@ -359,22 +379,17 @@ * Get the value of this Field as an int. If the field is static, * <code>o</code> will be ignored. * - * @param o - * the object to get the value of this Field from + * @param o the object to get the value of this Field from * @return the value of the Field - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte, short, char, or int field of - * <code>o</code>, or if <code>o</code> is not an instance - * of the declaring class of this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, or + * int field of <code>o</code>, or if <code>o</code> is not an + * instance of the declaring class of this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #get(Object) */ public int getInt(Object o) throws IllegalAccessException { @@ -385,22 +400,17 @@ * Get the value of this Field as a long. If the field is static, * <code>o</code> will be ignored. * - * @param o - * the object to get the value of this Field from + * @param o the object to get the value of this Field from * @return the value of the Field - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte, short, char, int, or long field of - * <code>o</code>, or if <code>o</code> is not an instance - * of the declaring class of this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * or long field of <code>o</code>, or if <code>o</code> is not an + * instance of the declaring class of this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #get(Object) */ public long getLong(Object o) throws IllegalAccessException { @@ -411,22 +421,17 @@ * Get the value of this Field as a float. If the field is static, * <code>o</code> will be ignored. * - * @param o - * the object to get the value of this Field from + * @param o the object to get the value of this Field from * @return the value of the Field - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte, short, char, int, long, or float field - * of <code>o</code>, or if <code>o</code> is not an - * instance of the declaring class of this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * long, or float field of <code>o</code>, or if <code>o</code> is + * not an instance of the declaring class of this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #get(Object) */ public float getFloat(Object o) throws IllegalAccessException { @@ -437,22 +442,18 @@ * Get the value of this Field as a double. If the field is static, * <code>o</code> will be ignored. * - * @param o - * the object to get the value of this Field from + * @param o the object to get the value of this Field from * @return the value of the Field - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte, short, char, int, long, float, or - * double field of <code>o</code>, or if <code>o</code> is - * not an instance of the declaring class of this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * long, float, or double field of <code>o</code>, or if + * <code>o</code> is not an instance of the declaring class of this + * field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #get(Object) */ public double getDouble(Object o) throws IllegalAccessException { @@ -460,50 +461,41 @@ } /** - * Set the value of this Field. If it is a primitive field, the value will - * be unwrapped from the passed object (boolean = java.lang.Boolean). - * <p> + * Set the value of this Field. If it is a primitive field, the value + * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p> * * If the field is static, <code>o</code> will be ignored. Otherwise, if * <code>o</code> is null, you get a <code>NullPointerException</code>, - * and if it is incompatible with the declaring class of the field, you get - * an <code>IllegalArgumentException</code>. - * <p> + * and if it is incompatible with the declaring class of the field, you + * get an <code>IllegalArgumentException</code>.<p> * * Next, if this Field enforces access control, your runtime context is * evaluated, and you may have an <code>IllegalAccessException</code> if * you could not access this field in similar compiled code. This also - * occurs whether or not there is access control if the field is final. If - * the field is primitive, and unwrapping your argument fails, you will get - * an <code>IllegalArgumentException</code>; likewise, this error happens - * if <code>value</code> cannot be cast to the correct object type. If the - * field is static, and its class is uninitialized, you trigger class + * occurs whether or not there is access control if the field is final. + * If the field is primitive, and unwrapping your argument fails, you will + * get an <code>IllegalArgumentException</code>; likewise, this error + * happens if <code>value</code> cannot be cast to the correct object type. + * If the field is static, and its class is uninitialized, you trigger class * initialization, which may end in a - * <code>ExceptionInInitializerError</code>. - * <p> + * <code>ExceptionInInitializerError</code>.<p> * * Finally, the field is set with the widened value. This method accesses * the field of the declaring class, even if the instance passed in belongs * to a subclass which declares another field to hide this one. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if <code>value</code> cannot be converted by a widening - * conversion to the underlying type of the Field, or if - * <code>o</code> is not an instance of the class declaring - * this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if <code>value</code> cannot be + * converted by a widening conversion to the underlying type of + * the Field, or if <code>o</code> is not an instance of the class + * declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #setBoolean(Object, boolean) * @see #setByte(Object, byte) * @see #setChar(Object, char) @@ -552,22 +544,17 @@ * Set this boolean Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a boolean field, or if <code>o</code> is not - * an instance of the class declaring this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a boolean field, or if + * <code>o</code> is not an instance of the class declaring this + * field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setBoolean(Object o, boolean value) @@ -579,23 +566,17 @@ * Set this byte Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a byte, short, int, long, float, or double - * field, or if <code>o</code> is not an instance of the class - * declaring this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, int, long, + * float, or double field, or if <code>o</code> is not an instance + * of the class declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setByte(Object o, byte value) throws IllegalAccessException { @@ -606,23 +587,17 @@ * Set this char Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a char, int, long, float, or double field, or - * if <code>o</code> is not an instance of the class declaring - * this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a char, int, long, + * float, or double field, or if <code>o</code> is not an instance + * of the class declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setChar(Object o, char value) throws IllegalAccessException { @@ -633,23 +608,17 @@ * Set this short Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a short, int, long, float, or double field, or - * if <code>o</code> is not an instance of the class declaring - * this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a short, int, long, + * float, or double field, or if <code>o</code> is not an instance + * of the class declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setShort(Object o, short value) throws IllegalAccessException { @@ -660,23 +629,17 @@ * Set this int Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not an int, long, float, or double field, or if - * <code>o</code> is not an instance of the class declaring - * this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not an int, long, float, or + * double field, or if <code>o</code> is not an instance of the + * class declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setInt(Object o, int value) throws IllegalAccessException { @@ -687,23 +650,17 @@ * Set this long Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a long, float, or double field, or if - * <code>o</code> is not an instance of the class declaring - * this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a long, float, or double + * field, or if <code>o</code> is not an instance of the class + * declaring this field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setLong(Object o, long value) throws IllegalAccessException { @@ -714,22 +671,17 @@ * Set this float Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a float or long field, or if <code>o</code> - * is not an instance of the class declaring this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a float or long field, or + * if <code>o</code> is not an instance of the class declaring this + * field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setFloat(Object o, float value) throws IllegalAccessException { @@ -740,22 +692,17 @@ * Set this double Field. If the field is static, <code>o</code> will be * ignored. * - * @param o - * the object to set this Field on - * @param value - * the value to set this Field to - * @throws IllegalAccessException - * if you could not normally access this field (i.e. it is not - * public) - * @throws IllegalArgumentException - * if this is not a double field, or if <code>o</code> is not - * an instance of the class declaring this field - * @throws NullPointerException - * if <code>o</code> is null and this field requires an - * instance - * @throws ExceptionInInitializerError - * if accessing a static field triggered class initialization, - * which then failed + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a double field, or if + * <code>o</code> is not an instance of the class declaring this + * field + * @throws NullPointerException if <code>o</code> is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed * @see #set(Object, Object) */ public void setDouble(Object o, double value) throws IllegalAccessException { @@ -763,6 +710,35 @@ } /** + * Return the generic type of the field. If the field type is not a generic + * type, the method returns the same as <code>getType()</code>. + * + * @throws GenericSignatureFormatError if the generic signature does + * not conform to the format specified in the Virtual Machine + * specification, version 3. + * @since 1.5 + */ + public Type getGenericType() + { + String signature = getSignature(); + if (signature == null) + return getType(); + FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(), + signature); + return p.getFieldType(); + } + + /** + * Return the String in the Signature attribute for this field. If there + * is no Signature attribute, return null. + */ + private String getSignature() { + return vmField.getSignature(); + } + + + + /** * @see java.lang.reflect.AnnotatedElement#getAnnotation(java.lang.Class) */ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { Modified: trunk/core/src/classpath/vm/java/lang/reflect/Method.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/reflect/Method.java 2007-01-20 08:55:33 UTC (rev 3086) +++ trunk/core/src/classpath/vm/java/lang/reflect/Method.java 2007-01-27 07:54:10 UTC (rev 3087) @@ -38,6 +38,7 @@ package java.lang.reflect; +import gnu.java.lang.ClassHelper; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -104,7 +105,8 @@ * is a non-inherited member. * @return the class that declared this member */ - public Class getDeclaringClass() { + public Class<?> getDeclaringClass() + { return vmMethod.getDeclaringClass().asClass(); } @@ -112,7 +114,8 @@ * Gets the name of this method. * @return the name of this method */ - public String getName() { + public String getName() + { return vmMethod.getName(); } @@ -120,7 +123,8 @@ * Return the raw modifiers for this method. * @return the method's modifiers */ - private int getModifiersInternal() { + private int getModifiersInternal() + { return vmMethod.getModifiers(); } @@ -172,7 +176,8 @@ * Gets the return type of this method. * @return the type of this method */ - public Class getReturnType() { + public Class<?> getReturnType() + { return vmMethod.getReturnType().asClass(); } @@ -182,7 +187,8 @@ * * @return a list of the types of the method's parameters */ - public Class[] getParameterTypes() { + public Class<?>[] getParameterTypes() + { if (parameterTypes == null) { int cnt = vmMethod.getNoArguments(); ArrayList<Class> list = new ArrayList<Class>(cnt); @@ -201,7 +207,8 @@ * * @return a list of the types in the method's throws clause */ - public Class[] getExceptionTypes() { + public Class<?>[] getExceptionTypes() + { if (exceptionTypes == null) { final VmExceptions exceptions = vmMethod.getExceptions(); final int cnt = exceptions.getLength(); @@ -234,7 +241,18 @@ * @return <code>true</code> if they are equal; <code>false</code> if not */ public boolean equals(Object o) { - return (this == o); + if (!(o instanceof Method)) + return false; + Method that = (Method)o; + if (this.getDeclaringClass() != that.getDeclaringClass()) + return false; + if (!this.getName().equals(that.getName())) + return false; + if (this.getReturnType() != that.getReturnType()) + return false; + if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes())) + return false; + return true; } /** @@ -243,9 +261,9 @@ * * @return the hash code for the object */ - public int hashCode() { - final Class<?> declClass = getDeclaringClass(); - return declClass.getName().hashCode() ^ getName().hashCode(); + public int hashCode() + { + return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); } /** @@ -259,18 +277,17 @@ */ public String toString() { // 128 is a reasonable buffer initial size for constructor - StringBuffer sb = new StringBuffer(128); + StringBuilder sb = new StringBuilder(128); Modifier.toString(getModifiers(), sb).append(' '); - final Class<?> retType = getReturnType(); - final Class<?> declClass = getDeclaringClass(); - sb.append(retType.getName()).append(' '); - sb.append(declClass.getName()).append('.'); + sb.append(ClassHelper.getUserName(getReturnType())).append(' '); + sb.append(getDeclaringClass().getName()).append('.'); sb.append(getName()).append('('); - Class<?>[] c = getParameterTypes(); - if (c.length > 0) { - sb.append(c[0].getName()); + Class[] c = getParameterTypes(); + if (c.length > 0) + { + sb.append(ClassHelper.getUserName(c[0])); for (int i = 1; i < c.length; i++) - sb.append(',').append(c[i].getName()); + sb.append(',').append(ClassHelper.getUserName(c[i])); } sb.append(')'); c = getExceptionTypes(); @@ -282,6 +299,33 @@ return sb.toString(); } + public String toGenericString() + { + // 128 is a reasonable buffer initial size for constructor + StringBuilder sb = new StringBuilder(128); + Modifier.toString(getModifiers(), sb).append(' '); + Constructor.addTypeParameters(sb, getTypeParameters()); + sb.append(getGenericReturnType()).append(' '); + sb.append(getDeclaringClass().getName()).append('.'); + sb.append(getName()).append('('); + Type[] types = getGenericParameterTypes(); + if (types.length > 0) + { + sb.append(types[0]); + for (int i = 1; i < types.length; i++) + sb.append(',').append(types[i]); + } + sb.append(')'); + types = getGenericExceptionTypes(); + if (types.length > 0) + { + sb.append(" throws ").append(types[0]); + for (int i = 1; i < types.length; i++) + sb.append(',').append(types[i]); + } + return sb.toString(); + } + /** * Invoke the method. Arguments are automatically unwrapped and widened, * and the result is automatically wrapped, if needed.<p> @@ -353,9 +397,9 @@ * Return the String in the Signature attribute for this method. If there * is no Signature attribute, return null. */ - private String getSignature() { - //todo implement it - return null; + private String getSignature() + { + return vmMethod.getSignature(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-20 08:55:34
|
Revision: 3086 http://jnode.svn.sourceforge.net/jnode/?rev=3086&view=rev Author: lsantha Date: 2007-01-20 00:55:33 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Added REP prefix. Modified Paths: -------------- trunk/core/src/core/org/jnode/assembler/x86/X86TextAssembler.java Modified: trunk/core/src/core/org/jnode/assembler/x86/X86TextAssembler.java =================================================================== --- trunk/core/src/core/org/jnode/assembler/x86/X86TextAssembler.java 2007-01-17 01:27:32 UTC (rev 3085) +++ trunk/core/src/core/org/jnode/assembler/x86/X86TextAssembler.java 2007-01-20 08:55:33 UTC (rev 3086) @@ -1983,6 +1983,9 @@ case LOCK_PREFIX: str = "lock"; break; + case REP_PREFIX: + str = "rep"; + break; default: throw new IllegalArgumentException("Unknown prefix " + prefix); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-17 01:27:33
|
Revision: 3085 http://jnode.svn.sourceforge.net/jnode/?rev=3085&view=rev Author: ansari82 Date: 2007-01-16 17:27:32 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Latest compilable list Modified Paths: -------------- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-17 01:13:48 UTC (rev 3084) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-17 01:27:32 UTC (rev 3085) @@ -244,8 +244,8 @@ || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.isolate") || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler") || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm") -// && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm") + && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") ) { return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-17 01:13:49
|
Revision: 3084 http://jnode.svn.sourceforge.net/jnode/?rev=3084&view=rev Author: ansari82 Date: 2007-01-16 17:13:48 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Latest compilable list Modified Paths: -------------- branches/jikesRVM/core/src/classpath/vm/java/lang/ClassLoader.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java branches/jikesRVM/core/src/test/org/jnode/test/JikesTest.java Modified: branches/jikesRVM/core/src/classpath/vm/java/lang/ClassLoader.java =================================================================== --- branches/jikesRVM/core/src/classpath/vm/java/lang/ClassLoader.java 2007-01-16 23:32:46 UTC (rev 3083) +++ branches/jikesRVM/core/src/classpath/vm/java/lang/ClassLoader.java 2007-01-17 01:13:48 UTC (rev 3084) @@ -288,16 +288,21 @@ } /* Can the class been loaded by a parent? */ - try { - if ((parent == null) || skipParentLoader(name)) { + if ((parent == null) || skipParentLoader(name)) { + try { if (vmClassLoader.isSystemClassLoader()) { return vmClassLoader.loadClass(name, resolve).asClass(); } - } else { + } catch (ClassNotFoundException e) { + // e.printStackTrace(); + } + } + else { + try { return parent.loadClass(name, resolve); + } catch (ClassNotFoundException e) { + // e.printStackTrace(); } - } catch (ClassNotFoundException e) { - // e.printStackTrace(); } /* Still not found, we have to do it ourself. */ final Class c = findClass(name); Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-16 23:32:46 UTC (rev 3083) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-17 01:13:48 UTC (rev 3084) @@ -221,76 +221,31 @@ public static boolean compilableMethod(VmMethod vmMethod) { if ( -// vmMethod.getDeclaringClass().getName().startsWith("java.io") -// || vmMethod.getDeclaringClass().getName().startsWith("java.lang") -// || vmMethod.getDeclaringClass().getName().startsWith("java.net") -// || vmMethod.getDeclaringClass().getName().startsWith("java.nio") -// || vmMethod.getDeclaringClass().getName().startsWith("java.security") -// || vmMethod.getDeclaringClass().getName().startsWith("java.util") -// || vmMethod.getDeclaringClass().getName().startsWith("javax") -// || vmMethod.getDeclaringClass().getName().startsWith("gnu.classpath") -// || vmMethod.getDeclaringClass().getName().startsWith("gnu.java") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.assembler") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.boot") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.naming") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.plugin") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.protocol") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.security") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.system") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.util") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.bytecode") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.classmgr") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.compiler") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.isolate") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler") + vmMethod.getDeclaringClass().getName().startsWith("java.io") + || vmMethod.getDeclaringClass().getName().startsWith("java.lang") + || vmMethod.getDeclaringClass().getName().startsWith("java.net") + || vmMethod.getDeclaringClass().getName().startsWith("java.nio") + || vmMethod.getDeclaringClass().getName().startsWith("java.security") + || vmMethod.getDeclaringClass().getName().startsWith("java.util") + || vmMethod.getDeclaringClass().getName().startsWith("javax") + || vmMethod.getDeclaringClass().getName().startsWith("gnu.classpath") + || vmMethod.getDeclaringClass().getName().startsWith("gnu.java") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.assembler") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.boot") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.naming") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.plugin") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.protocol") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.security") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.system") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.util") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.bytecode") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.classmgr") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.compiler") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.isolate") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler") // || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm") -// && !( -// vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmReflection") -// && vmMethod.getName().contentEquals("invoke") //manipulates ESP, which Jikes needs to control -// ) - -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.A") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.B") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.C") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.H") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.I") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.J") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.L") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.M") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.O") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.R") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.S") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.U") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.Vi") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmA") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmE") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmJ") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmM") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmP") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmR") -// && !vmMethod.getName().contentEquals("invoke") //manipulates ESP, which Jikes needs to control -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSt") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystem") - vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader$") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") -// - && ( - vmMethod.getName().contains("init") - || vmMethod.getName().startsWith("a") - || vmMethod.getName().startsWith("c") - || vmMethod.getName().startsWith("d") - || vmMethod.getName().startsWith("f") - || vmMethod.getName().startsWith("g") - || vmMethod.getName().startsWith("i") - || vmMethod.getName().startsWith("l") - || vmMethod.getName().startsWith("p") - || vmMethod.getName().startsWith("r") - || vmMethod.getName().startsWith("s") - - ) - +// && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") ) { return true; @@ -301,7 +256,7 @@ public void compileBootstrap(VmMethod method, NativeStream os, int level) { VM_BootstrapClassLoader.fromJikesCompiler = method.getDeclaringClass().getLoader(); - System.out.println(method.getFullName()); +// System.out.println(method.getFullName()); int start = os.getLength(); final CompiledMethod cm; final boolean abstractM = method.isAbstract(); Modified: branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-16 23:32:46 UTC (rev 3083) +++ branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-17 01:13:48 UTC (rev 3084) @@ -211,7 +211,7 @@ } if (vmMethod.getNativeCodeOptLevel() < optLevel) { if(cmps[index] == optCompiler && - !(vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test") + (!vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test") || vmMethod.hasNoOptCompilePragma())) cmp = fallbackCompiler; else Modified: branches/jikesRVM/core/src/test/org/jnode/test/JikesTest.java =================================================================== --- branches/jikesRVM/core/src/test/org/jnode/test/JikesTest.java 2007-01-16 23:32:46 UTC (rev 3083) +++ branches/jikesRVM/core/src/test/org/jnode/test/JikesTest.java 2007-01-17 01:13:48 UTC (rev 3084) @@ -31,6 +31,7 @@ System.out.println("jikesAllocMultiArray expect true, return "+(jikesAllocMultiArray()[1][1]==localSTATIC?true:false)); System.out.println("jikesMonitor expect true, return "+jikesMonitor()); System.out.print( "jikesTryCatchException expect true, return ");jikesTryCatch(); + System.out.print( "jikesComplexException expect true, return ");jikesComplexException(true); t0 = time();System.out.print("jikestestSmallLoop:"+jikestestsmallloop()+" time:");t1 = time();System.out.println(t1 - t0); t0 = time();System.out.print("jikestestBigLoop: "+jikestestbigloop() +" time:");t1 = time();System.out.println(t1 - t0); sayHi2(); @@ -77,6 +78,21 @@ } } + private static boolean jikesComplexException(boolean first) { + + boolean local = first; + try{ + if(local) { + jikesTryException(); + } else { + jikesTryException(); + } + } catch (Exception e) { + //Do nothing + } + return local; + } + private static boolean jikesMonitor() { Object a = new Object(); boolean b = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:32:48
|
Revision: 3083 http://jnode.svn.sourceforge.net/jnode/?rev=3083&view=rev Author: ansari82 Date: 2007-01-16 15:32:46 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Added support for explicit opt and fallback compilers, and use them for boot image and runtime compilation Modified Paths: -------------- branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java branches/jikesRVM/core/src/core/org/jnode/vm/VmArchitecture.java branches/jikesRVM/core/src/core/org/jnode/vm/x86/VmX86Architecture.java Modified: branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java =================================================================== --- branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2007-01-16 23:20:01 UTC (rev 3082) +++ branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2007-01-16 23:32:46 UTC (rev 3083) @@ -197,15 +197,6 @@ throws ClassNotFoundException { final NativeCodeCompiler[] compilers = arch.getCompilers(); final int optLevel = compilers.length - 1; - // Use the most optimizing compiler here - final NativeCodeCompiler compiler = compilers[optLevel]; - NativeCodeCompiler backup, test = null; - for(int i = 0; i < compilers.length; i++) { - if(compilers[i] instanceof X86Level1ACompiler) { - test = compilers[i]; break; - } - } - if(test==null)backup=null; else backup=test; int oldCount; int newCount; @@ -233,11 +224,11 @@ for (int i = 0; i < cnt; i++) { final VmMethod method = vmClass.getDeclaredMethod(i); mcnt++; - if(compiler instanceof JikesRVMOptCompiler && !JikesRVMOptCompiler.compilableMethod(method)) { - backup.compileBootstrap(method, os, optLevel); + if(method.hasNoOptCompilePragma() || !JikesRVMOptCompiler.compilableMethod(method)) { + arch.getFallbackCompiler().compileBootstrap(method, os, optLevel); } else { - compiler.compileBootstrap(method, os, optLevel); + arch.getOptCompiler().compileBootstrap(method, os, optLevel); } } vmClass.setCompiled(); Modified: branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-16 23:20:01 UTC (rev 3082) +++ branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-16 23:32:46 UTC (rev 3083) @@ -37,7 +37,8 @@ private final ObjectResolver resolver; private final NativeCodeCompiler[] compilers; - + + private final NativeCodeCompiler optCompiler, fallbackCompiler; private final NativeCodeCompiler[] testCompilers; private static boolean started = false; @@ -53,6 +54,8 @@ final VmArchitecture arch = VmMagic.currentProcessor() .getArchitecture(); this.compilers = arch.getCompilers(); + optCompiler = arch.getOptCompiler(); + fallbackCompiler = arch.getFallbackCompiler(); this.testCompilers = arch.getTestCompilers(); } @@ -207,10 +210,10 @@ index = cmps.length - 1; } if (vmMethod.getNativeCodeOptLevel() < optLevel) { - if(cmps[index] instanceof JikesRVMOptCompiler && - !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test") - || vmMethod.hasNoOptCompilePragma()) - cmp = cmps[index-1]; + if(cmps[index] == optCompiler && + !(vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test") + || vmMethod.hasNoOptCompilePragma())) + cmp = fallbackCompiler; else cmp = cmps[index]; cmp.compileRuntime(vmMethod, resolver, optLevel, null); Modified: branches/jikesRVM/core/src/core/org/jnode/vm/VmArchitecture.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/VmArchitecture.java 2007-01-16 23:20:01 UTC (rev 3082) +++ branches/jikesRVM/core/src/core/org/jnode/vm/VmArchitecture.java 2007-01-16 23:32:46 UTC (rev 3083) @@ -317,4 +317,8 @@ protected VmMultiMediaSupport createMultiMediaSupport() { return new VmJavaMultiMediaSupport(); } + + //Get specific compilers + public abstract NativeCodeCompiler getFallbackCompiler(); + public abstract NativeCodeCompiler getOptCompiler(); } Modified: branches/jikesRVM/core/src/core/org/jnode/vm/x86/VmX86Architecture.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/x86/VmX86Architecture.java 2007-01-16 23:20:01 UTC (rev 3082) +++ branches/jikesRVM/core/src/core/org/jnode/vm/x86/VmX86Architecture.java 2007-01-16 23:32:46 UTC (rev 3083) @@ -105,6 +105,7 @@ /** The compilers */ private final NativeCodeCompiler[] compilers; + private final NativeCodeCompiler optCompiler, fallbackCompiler; /** The compilers under test */ private final NativeCodeCompiler[] testCompilers; @@ -151,6 +152,8 @@ this.compilers[2] = new JikesRVMOptCompiler(); this.compilers[3] = this.compilers[2]; + optCompiler = compilers[2]; + fallbackCompiler = compilers[1]; // this.compilers[3] = this.compilers[1]; this.testCompilers = null; @@ -453,4 +456,12 @@ return super.createMultiMediaSupport(); } } + + public NativeCodeCompiler getFallbackCompiler() { + return fallbackCompiler; + } + + public NativeCodeCompiler getOptCompiler() { + return optCompiler; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:20:02
|
Revision: 3082 http://jnode.svn.sourceforge.net/jnode/?rev=3082&view=rev Author: ansari82 Date: 2007-01-16 15:20:01 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Large commit of all current fixes to make boot image compile Modified Paths: -------------- branches/jikesRVM/all/conf/x86/menu-cdrom.lst branches/jikesRVM/all/conf/x86/menu.lst branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java branches/jikesRVM/builder/src/builder/org/jnode/build/VMwareBuilderTask.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethod.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethods.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_Runtime.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Class.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Field.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_FieldReference.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MemberReference.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MethodReference.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Primitive.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Type.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_TypeReference.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_BURS_Helpers.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_ClassLoaderProxy.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_DynamicTypeCheckExpansion.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_GenericStackManager.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_NormalizeConstants.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/VM_OptCompiledMethod.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/ir/OPT_BC2IR.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/ir/OPT_ClassConstantOperand.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/ir/OPT_LongConstantOperand.java branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/ir/OPT_RegisterPool.java branches/jikesRVM/core/src/native/x86/ints32.asm branches/jikesRVM/core/src/native/x86/vm-ints.asm branches/jikesRVM/core/src/native/x86/vm.asm branches/jikesRVM/core/src/test/org/jnode/test/core/CompilerTest.java Modified: branches/jikesRVM/all/conf/x86/menu-cdrom.lst =================================================================== (Binary files differ) Modified: branches/jikesRVM/all/conf/x86/menu.lst =================================================================== --- branches/jikesRVM/all/conf/x86/menu.lst 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/all/conf/x86/menu.lst 2007-01-16 23:20:01 UTC (rev 3082) @@ -4,7 +4,7 @@ # --------------------------- title JNode (default) -kernel (hd0,0)/jnode32.gz mp=no +kernel (hd0,0)/jnode32.gz mp=no kdb module (hd0,0)/default.jgz # --------------------------- Modified: branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java =================================================================== --- branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -213,8 +213,6 @@ do { again = false; oldCount = clsMgr.getLoadedClassCount(); - for (VmType< ? > vmClass : clsMgr.getLoadedClasses()) - vmClass.setInBootImage(true); for (VmType< ? > vmClass : clsMgr.getLoadedClasses()) { vmClass.link(); final boolean compHigh = isCompileHighOptLevel(vmClass); @@ -550,7 +548,8 @@ // Load the jarfile as byte-array // copyJarFile(blockedObjects, piRegistry); - + for (VmType< ? > vmClass : clsMgr.getLoadedClasses()) + vmClass.setInBootImage(true); // Now emit all object images to the actual image emitObjects(os, arch, blockedObjects, false); Modified: branches/jikesRVM/builder/src/builder/org/jnode/build/VMwareBuilderTask.java =================================================================== --- branches/jikesRVM/builder/src/builder/org/jnode/build/VMwareBuilderTask.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/builder/src/builder/org/jnode/build/VMwareBuilderTask.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -111,7 +111,7 @@ if((logFile != null) && (logFile.trim().length() != 0)) { - put(w, "serial0.present", "FALSE"); + put(w, "serial0.present", "TRUE"); put(w, "serial0.fileType", "file"); put(w, "serial0.fileName", logFile); } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/JikesRVMOptCompiler.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -92,9 +92,9 @@ OPT_CompilationPlan compPlan = new OPT_CompilationPlan(jikesMethod, optimizationPlan, null, options); //Compile with Jikes - VM_CompiledMethod jikescm = optCompileWithFallBackInternal(jikesMethod, compPlan); + /*VM_CompiledMethod jikes*/cm = optCompileWithFallBackInternal(jikesMethod, compPlan); //Build necessary result for JNode VM from Jikes compiled output - cm = ((VM_OptCompiledMethod)jikescm).buildJnodeCM((X86Assembler)nos, getEntryPoints()); + /*cm = */((VM_OptCompiledMethod)cm).buildJnodeCM((X86Assembler)nos, getEntryPoints()); //Uninitialise Jikes' VM_Magic // VM_Magic.uninit(); compilationInProgress = false; @@ -200,15 +200,17 @@ } @Override public String[] getCompilerPackages() { - return new String[] { "org.jnode.vm.x86.compiler", - "com.ibm.JikesRVM", - "com.ibm.JikesRVM.adaptive", - "com.ibm.JikesRVM.classloader", - "com.ibm.JikesRVM.memoryManagers.mmInterface", -// "com.ibm.JikesRVM.opt", -// "com.ibm.JikesRVM.opt.ir", - "com.ibm.JikesRVM.OSR", - "com.ibm.JikesRVM.util"}; + return new String[] { +// "org.jnode.vm.x86.compiler", +// "com.ibm.JikesRVM", +// "com.ibm.JikesRVM.adaptive", +// "com.ibm.JikesRVM.classloader", +// "com.ibm.JikesRVM.memoryManagers.mmInterface", +// "com.ibm.JikesRVM.opt", +// "com.ibm.JikesRVM.opt.ir", +// "com.ibm.JikesRVM.OSR", +// "com.ibm.JikesRVM.util" + }; } //-------------------------------------------------------------------------------------------// @@ -219,62 +221,76 @@ public static boolean compilableMethod(VmMethod vmMethod) { if ( -// && !( vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler.l1a.X86Byte") -// && vmMethod.getName().contains("other")) - vmMethod.getDeclaringClass().getName().startsWith("java.io") - || vmMethod.getDeclaringClass().getName().startsWith("java.lang") -// && !(vmMethod.getDeclaringClass().getName().startsWith("java.lang.ClassLoader") -// && vmMethod.getName().contains("loadClass")) -// && !(vmMethod.getDeclaringClass().getName().startsWith("java.lang.String") -// && vmMethod.getName().contains("init")) - || vmMethod.getDeclaringClass().getName().startsWith("java.net") - || vmMethod.getDeclaringClass().getName().startsWith("java.nio") - || vmMethod.getDeclaringClass().getName().startsWith("java.security") - && !vmMethod.getDeclaringClass().getName().startsWith("java.security.Permissions") - || vmMethod.getDeclaringClass().getName().startsWith("java.util") - || vmMethod.getDeclaringClass().getName().startsWith("javax") - || vmMethod.getDeclaringClass().getName().startsWith("gnu.classpath") - || vmMethod.getDeclaringClass().getName().startsWith("gnu.java") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.assembler") - && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.assembler.x86.X86B") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.boot.") - && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.boot.Main") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.naming") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.plugin") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.protocol") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.security") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.system") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.util") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.bytecode") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.classmgr") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.compiler") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.isolate") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler") - || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler") - && !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler.l1a.X86Byte") -// || (vmMethod.getDeclaringClass().getName().lastIndexOf('.') > 0 ? -// vmMethod.getDeclaringClass().getName().substring(0, -// vmMethod.getDeclaringClass().getName().lastIndexOf('.')) -// : "").contentEquals("org.jnode.vm") +// vmMethod.getDeclaringClass().getName().startsWith("java.io") +// || vmMethod.getDeclaringClass().getName().startsWith("java.lang") +// || vmMethod.getDeclaringClass().getName().startsWith("java.net") +// || vmMethod.getDeclaringClass().getName().startsWith("java.nio") +// || vmMethod.getDeclaringClass().getName().startsWith("java.security") +// || vmMethod.getDeclaringClass().getName().startsWith("java.util") +// || vmMethod.getDeclaringClass().getName().startsWith("javax") +// || vmMethod.getDeclaringClass().getName().startsWith("gnu.classpath") +// || vmMethod.getDeclaringClass().getName().startsWith("gnu.java") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.assembler") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.boot") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.naming") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.plugin") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.protocol") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.security") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.system") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.util") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.bytecode") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.classmgr") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.compiler") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.isolate") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.x86.compiler") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm") +// && !( +// vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmReflection") +// && vmMethod.getName().contentEquals("invoke") //manipulates ESP, which Jikes needs to control +// ) + +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.A") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.B") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.C") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.H") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.I") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.J") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.L") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.M") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.O") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.R") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.S") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.U") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.Vi") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmA") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmE") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmJ") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmM") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmP") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmR") +// && !vmMethod.getName().contentEquals("invoke") //manipulates ESP, which Jikes needs to control +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSt") +// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystem") + vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader$") + || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.VmSystemClassLoader") +// + && ( + vmMethod.getName().contains("init") + || vmMethod.getName().startsWith("a") + || vmMethod.getName().startsWith("c") + || vmMethod.getName().startsWith("d") + || vmMethod.getName().startsWith("f") + || vmMethod.getName().startsWith("g") + || vmMethod.getName().startsWith("i") + || vmMethod.getName().startsWith("l") + || vmMethod.getName().startsWith("p") + || vmMethod.getName().startsWith("r") + || vmMethod.getName().startsWith("s") + + ) - -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.I") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.M") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.P") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.S") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.VmP") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.VmS") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.VmThreadQ") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.VmThreadV") -// || vmMethod.getDeclaringClass().getName().startsWith("org.jnode.vm.scheduler.VmThread") -// && ( -// vmMethod.isStatic() -// || vmMethod.getName().startsWith("a") -// || vmMethod.getName().startsWith("c") -// || vmMethod.getName().startsWith("d") -// || vmMethod.getName().startsWith("g") -// -// ) ) { return true; @@ -330,7 +346,7 @@ //Try and get from constant pool, should be there. if(this instanceof JikesRVMOptCompiler) { - int catchid = cm.getJikesCM().getETable()[i*4+3]; + int catchid = ((VM_CompiledMethod)cm)/*.getJikesCM()*/.getETable()[i*4+3]; String jnodeType = VM_Type.getVM_Type(catchid).getJnodeType().getName(); for(int j = 0; j < bc.getCP().getLength(); j++) { if (bc.getCP().getAny(j) instanceof VmConstClass && @@ -450,7 +466,7 @@ //Try and get from constant pool, should be there. if(this instanceof JikesRVMOptCompiler) { - int catchid = cm.getJikesCM().getETable()[i*4+3]; + int catchid = ((VM_CompiledMethod)cm)/*.getJikesCM()*/.getETable()[i*4+3]; String jnodeType = VM_Type.getVM_Type(catchid).getJnodeType().getName(); for(int j = 0; j < bc.getCP().getLength(); j++) { if (bc.getCP().getAny(j) instanceof VmConstClass && Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethod.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethod.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethod.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -1,5 +1,7 @@ package com.ibm.JikesRVM; +import java.util.Enumeration; + import org.jnode.assembler.Label; import org.jnode.assembler.NativeStream; import org.jnode.assembler.x86.X86Assembler; @@ -25,16 +27,23 @@ import com.ibm.JikesRVM.classloader.VM_Method; import com.ibm.JikesRVM.classloader.VM_NormalMethod; import com.ibm.JikesRVM.classloader.VM_Type; +import com.ibm.JikesRVM.classloader.VM_TypeReference; import com.ibm.JikesRVM.opt.VM_OptCompiledMethod; +import com.ibm.JikesRVM.opt.ir.MIR_Move; import com.ibm.JikesRVM.opt.ir.OPT_BasicBlock; import com.ibm.JikesRVM.opt.ir.OPT_IR; import com.ibm.JikesRVM.opt.ir.OPT_Instruction; import com.ibm.JikesRVM.opt.ir.OPT_InstructionEnumeration; +import com.ibm.JikesRVM.opt.ir.OPT_Operand; import com.ibm.JikesRVM.opt.ir.OPT_Operators; +import com.ibm.JikesRVM.opt.ir.OPT_PhysicalRegisterSet; +import com.ibm.JikesRVM.opt.ir.OPT_Register; +import com.ibm.JikesRVM.opt.ir.OPT_RegisterOperand; +import com.ibm.JikesRVM.opt.ir.OPT_StackLocationOperand; -public abstract class VM_CompiledMethod implements X86CompilerConstants { +public abstract class VM_CompiledMethod extends CompiledMethod implements X86CompilerConstants { - protected CompiledMethod jnodecm; + //protected CompiledMethod jnodecm; public static final int optlevel = 3; @@ -52,7 +61,7 @@ public final static int NUM_COMPILER_TYPES = 4; - protected final int cmid; +// protected final int cmid; /* * constants for bitField1 @@ -83,8 +92,9 @@ */ protected int bitField1; - public VM_CompiledMethod(int id, VM_Method m) { - cmid = id; + public VM_CompiledMethod(VM_Method m) { + super(optlevel); +// cmid = id; method = m; } @@ -94,7 +104,7 @@ * Return the compiled method id for this compiled method */ public int getId() { - return cmid; + return getCompiledCodeId();//return cmid; } /** @@ -362,13 +372,7 @@ return null; } - public CompiledMethod getJnodeCompiledMethod() { - return jnodecm; - } - public void setJnodeCompiledMethod(CompiledMethod jnodeCompiledMethod) { - this.jnodecm = jnodeCompiledMethod; - } /* This is a hacked method for porting the opt compiler into Jnode. * It only does what is needed in terms of the port, be very careful when using it. @@ -378,7 +382,7 @@ //Create jikes method based on jnode method VM_NormalMethod jikesmethod = (VM_NormalMethod)VM_Method.buildFromJnodeMethod(jnodecm.getMethod()); //Create jikes compiled-method based on jnode compiled-method and jikes method above - VM_CompiledMethod jikescm = new VM_OptCompiledMethod(jnodecm.getId(), jikesmethod); + VM_CompiledMethod jikescm = new VM_OptCompiledMethod(jikesmethod); //Copy machine code if it exists if (jnodecm.getCompiledCode() != null) { @@ -418,10 +422,10 @@ return eTable; } - public CompiledMethod buildJnodeCM(X86Assembler os, EntryPoints ep) { + public void/*CompiledMethod*/ buildJnodeCM(X86Assembler os, EntryPoints ep) { final VmMethod jnodeMethod = (VmMethod)method.getJnodeMember(); - jnodecm.setJikesCM(this); +// jnodecm.setJikesCM(this); final VmMethodCode code = new VmMethodCode(); final Label startLabel = new Label(jnodeMethod.getMangledName()+"_"+"$$start"); final Label startCodeLabel = new Label(jnodeMethod.getMangledName()+"_"+"$$code"); @@ -430,12 +434,13 @@ final int count; if (eTable != null) count = eTable.length >> 2; else count = 0; - CompiledExceptionHandler[] ceh = new CompiledExceptionHandler[count]; + CompiledExceptionHandler[] ceh = null; + if(count != 0) ceh = new CompiledExceptionHandler[count]; for(int i = 0; i < count; i++) ceh[i] = new CompiledExceptionHandler(); codeObject = os.startObject(ep.getVmMethodCodeClass()); os.setObjectRef(code); - jnodecm.setCodeStart(os.setObjectRef(startLabel)); + /*jnodecm.*/setCodeStart(os.setObjectRef(startLabel)); final int startOffset = os.getLength(); // Set startCode label @@ -467,7 +472,7 @@ } } } - jnodecm.setExceptionHandlers(ceh); + /*jnodecm.*/setExceptionHandlers(ceh); } //Build bc-address mapping @@ -484,7 +489,7 @@ bci = i.position.bcIndex; } if(bci >= 0 && mci >= ((VM_OptCompiledMethod)this).getEndPrologueOffset() && depth >= 0) - jnodecm.add(jnodeMethod, bci, mci+offset, 0); + /*jnodecm.*/add(jnodeMethod, bci, mci+offset, 0); //Print final IR if outputting to text instead of binary/machine code if(os.isTextStream()) { @@ -500,12 +505,31 @@ // Now create the default exception handler Label handlerLabel = new Label(jnodeMethod.getMangledName()+"_$$def-ex-handler"); - jnodecm.setDefExceptionHandler(os.setObjectRef(handlerLabel)); + /*jnodecm.*/setDefExceptionHandler(os.setObjectRef(handlerLabel)); if(temp_ir.stackManager.frameIsRequired()) { - int frameSize = temp_ir.stackManager.getFrameFixedSize()-INTSIZE; - os.writeLEA(X86Register.ESP, X86Register.EBP, -frameSize); - os.writePOP(X86Register.EBX); - os.writePOP(X86Register.ESI); + int frameSize = temp_ir.stackManager.getFrameFixedSize(); + os.writeLEA(X86Register.ESP, X86Register.EBP, +INTSIZE); + + OPT_PhysicalRegisterSet phys = temp_ir.regpool.getPhysicalRegisterSet(); + int nNonvolatileGPRS = temp_ir.compiledMethod.getNumberOfNonvolatileGPRs(); + + int n = nNonvolatileGPRS - 1; + for (Enumeration e = phys.enumerateNonvolatileGPRsBackwards(); + e.hasMoreElements() && n >= 0 ; n--) { + OPT_Register nv = (OPT_Register)e.nextElement(); + int nvoffset = temp_ir.stackManager.getNonvolatileGPROffset(n); +// OPT_Operand M = new OPT_StackLocationOperand(true, -offset, 4); + os.writeMOV(VM_SizeConstants.BYTES_IN_ADDRESS, + getJnodeRegister(nv, phys), getJnodeRegister(phys.getESP(), + phys), -nvoffset); +// os.writeMOV(getJnodeRegister(nv, phys), X86Register.ESP, nvoffset); +// inst.insertBefore(MIR_Move.create(IA32_MOV, new OPT_RegisterOperand(nv, VM_TypeReference.Int), M)); + + + +// os.writePOP(X86Register.EBX); +// os.writePOP(X86Register.ESI); + } } //Restore monitor lock if necessary (needed because of def-exhandling) if(method.isSynchronized()) { @@ -527,7 +551,7 @@ os.writePOP(adx); os.writePOP(aax); } - os.writeLEA(X86Register.ESP, X86Register.EBP, 4); +// os.writeLEA(X86Register.ESP, X86Register.EBP, 4); os.writePOP(X86Register.EBP); final int soffset = (VmArray.DATA_OFFSET * 4) + (X86JumpTable.VM_ATHROW_NOTRACE_IDX << 2); os.writeJMP(X86Register.EDI, soffset); @@ -535,12 +559,36 @@ //Finish off codeObject.markEnd(); - jnodecm.setCodeEnd(os.setObjectRef(endLabel)); + /*jnodecm.*/setCodeEnd(os.setObjectRef(endLabel)); temp_ir = null; - return jnodecm; + //return jnodecm; } + private X86Register.GPR getJnodeRegister(OPT_Register r, OPT_PhysicalRegisterSet phys) { + if(r==phys.getEAX()) + return X86Register.EAX; + else if(r==phys.getEBX()) + return X86Register.EBX; + else if(r==phys.getECX()) + return X86Register.ECX; + else if(r==phys.getEDX()) + return X86Register.EDX; + else if(r==phys.getEDI()) + return X86Register.EDI; + else if(r==phys.getESI()) + return X86Register.ESI; + else if(r==phys.getESP()) + return X86Register.ESP; + else if(r==phys.getEBP()) + return X86Register.EBP; + else { + try {throw new Exception("VM_CompiledMethod: getJnodeRegister: Unknown reg: "+r.toString());} + catch(Exception e){System.out.println(e.getMessage()); System.exit(-1);} + } + return null; + } + public final int getSharedStaticsOffset(VmSharedStaticsEntry entry, X86Assembler os) { if (os.isCode32()) { return (VmArray.DATA_OFFSET * 4) Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethods.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethods.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_CompiledMethods.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -16,10 +16,7 @@ public static VM_CompiledMethod createCompiledMethod(VM_Method m, int compilerType) { VM._assert(jnodeCompiledMethods != null); - CompiledMethod jnodecm = new CompiledMethod(compilerType); - int id = jnodecm.getCompiledCodeId(); - VM_CompiledMethod jikescm = new VM_OptCompiledMethod(id, m); - jikescm.setJnodeCompiledMethod(jnodecm); + VM_CompiledMethod jikescm = new VM_OptCompiledMethod(m); return jikescm; } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_Runtime.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_Runtime.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/VM_Runtime.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -48,7 +48,7 @@ if (!rhs.isResolved()) { rhs.resolve(); } - return lhs.getClass().isAssignableFrom(rhs.getClass()); + return lhs.getJnodeType().isAssignableFrom(rhs.getJnodeType()); } public static Object buildMultiDimensionalArray(int methodId, int[] dimensions, VM_Array type) { Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Class.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Class.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Class.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -122,6 +122,33 @@ } } + public final double getDoubleLiteral(int i) { + Object cpEntry = jnodeType.getCP().getAny(i); + return ((VmConstDouble)cpEntry).doubleValue(); + } + + public final long getLongLiteral(int i) { + Object cpEntry = jnodeType.getCP().getAny(i); + return ((VmConstLong)cpEntry).longValue(); + } + + public final float getFloatLiteral(int i) { + Object cpEntry = jnodeType.getCP().getAny(i); + return ((VmConstFloat)cpEntry).floatValue(); + } + + public final int getIntLiteral(int i) { + Object cpEntry = jnodeType.getCP().getAny(i); + return ((VmConstInt)cpEntry).intValue(); + } + + public final String getStringLiteral(int i) { + Object cpEntry = jnodeType.getCP().getAny(i); + VmSharedStatics vmStatics = jnodeType.getLoader().getSharedStatics(); + int val = ((VmConstString)cpEntry).getSharedStaticsIndex(); + return (String)vmStatics.getRawObject(val); + } + /** * Get offset of a literal constant, in bytes. * Offset is with respect to virtual machine's "table of contents" (jtoc). @@ -129,57 +156,14 @@ public final Offset getLiteralOffset(int i) { Object cpEntry = jnodeType.getCP().getAny(i); - if(cpEntry instanceof VmConstDouble){ - double val = ((VmConstDouble)cpEntry).doubleValue(); - long raw_val = Double.doubleToLongBits(val); - int idx = VM_Statics.findOrCreateDoubleLiteral(raw_val); - return Offset.fromIntZeroExtend(idx); - } - else if(cpEntry instanceof VmConstLong) { - long val = ((VmConstLong)cpEntry).longValue(); - int idx = VM_Statics.findOrCreateLongLiteral(val); - return Offset.fromIntZeroExtend(idx); - } - else if(cpEntry instanceof VmConstFloat) { - float val = ((VmConstFloat)cpEntry).floatValue(); - int raw_val = Float.floatToIntBits(val); - int idx = VM_Statics.findOrCreateFloatLiteral(raw_val); - return Offset.fromIntZeroExtend(idx); - } - else if(cpEntry instanceof VmConstInt) { - int val = ((VmConstInt)cpEntry).intValue(); - int idx = VM_Statics.findOrCreateIntLiteral(val); - return Offset.fromIntZeroExtend(idx); - } - else if(cpEntry instanceof VmConstString) { + if(cpEntry instanceof VmConstString) { VmSharedStatics vmStatics = jnodeType.getLoader().getSharedStatics(); int val = ((VmConstString)cpEntry).getSharedStaticsIndex(); - String str = (String)vmStatics.getRawObject(val); - VM_Atom atom = VM_Atom.findOrCreateAsciiAtom(str); - try { - VM_Statics.findOrCreateStringLiteral(atom, str); - return Offset.fromIntZeroExtend(val*4 + VmArray.DATA_OFFSET*4); - } - catch (Exception e) { - e.printStackTrace(); - } + return Offset.fromIntZeroExtend(val*4 + VmArray.DATA_OFFSET*4); } - else if(cpEntry instanceof VmConstClass) { - VM_Type jikesType = null; - if(((VmConstClass)cpEntry).isResolved()){ - jikesType = VM_Type.buildFromJnodeType(((VmConstClass)cpEntry).getResolvedVmClass()); - } else { - ((VmConstClass)cpEntry).resolve(this.jnodeType.getLoader()); - jikesType = VM_Type.buildFromJnodeType(((VmConstClass)cpEntry).getResolvedVmClass()); - } - int id = jikesType.getTypeRef().getId(); - int idx = VM_Statics.findOrCreateClassLiteral(id); - return Offset.fromIntZeroExtend(idx); - } else { throw new Error("TODO: "+cpEntry+" "+cpEntry.getClass()); } - return null; } public VM_Method getClassInitializerMethod() { @@ -191,9 +175,8 @@ } public void resolve() { - jnodeType.link(); -// jnodeType.prepare(); -// jnodeType.prepareForInstantiation(); +// jnodeType.link(); + jnodeType.prepare(); } /** @@ -226,10 +209,6 @@ return VM_Class.buildFromJnodeClass(jnodeType.getSuperClass()); } - public boolean isInterface() { - return jnodeType.isInterface(); - } - public boolean isFinal() { return jnodeType.isFinal(); } @@ -323,7 +302,7 @@ @Override public void instantiate() { - jnodeType.link(); + jnodeType.prepare(); } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Field.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Field.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Field.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -37,7 +37,7 @@ VM_Atom methodDescriptor = VM_Atom.findOrCreateAsciiAtom(jnodeField.getSignature()); VM_MemberReference memRef = VM_MemberReference.findOrCreate(declaringClass.getTypeRef(), methodName, methodDescriptor); if(memRef.asFieldReference().isResolved()) - return memRef.asFieldReference().getResolvedMember(); + return memRef.asFieldReference().peekResolvedField(); VM_Field jikesField = new VM_Field(declaringClass, memRef, jnodeField.getModifiers(), jnodeField); return jikesField; } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_FieldReference.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_FieldReference.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_FieldReference.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -52,8 +52,8 @@ try { throw new Exception("VM_FieldReference: resolve"); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + + e.printStackTrace(); System.exit(-1); } return null; } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MemberReference.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MemberReference.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MemberReference.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -260,7 +260,8 @@ if(VM.writingBootImage && !thisClass.getJnodeType().isAlwaysInitialized() && resolvedThis.isStatic() - && !thisClass.getJnodeType().isSharedStatics()) { +// && !thisClass.getJnodeType().isSharedStatics() + ) { // JNODE Isolate-specific // This class is an isolate type, so the state of the isolated object // needs to be checked, if a static field from it is being accessed, Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MethodReference.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MethodReference.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_MethodReference.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -188,7 +188,7 @@ throw new Exception("VM_MethodReference.resolve() not implemented!"); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); + e.printStackTrace(); System.exit(-1); } return null; // Hasn't been resolved yet. Do it now triggering class loading if necessary. Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Primitive.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Primitive.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Primitive.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -167,7 +167,6 @@ @Override public void resolve() { jnodeType.prepare(); - jnodeType.prepareForInstantiation(); } @Override Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Type.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Type.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_Type.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -198,11 +198,11 @@ * Is this class part of the virtual machine's boot image? */ public final boolean isInBootImage() throws UninterruptiblePragma { - return false;//return jnodeType.isInBootImage(); + return jnodeType.isInBootImage(); } public final Class getClassForType() { - return null;//jnodeType.asClass(); + return jnodeType.asClass(); } public boolean isInstantiated() { @@ -317,5 +317,9 @@ return jnodeType.isSharedStatics(); } + public boolean isInterface() { + return jnodeType.isInterface(); + } + } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_TypeReference.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_TypeReference.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/classloader/VM_TypeReference.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -559,7 +559,7 @@ // objects when not running the VM (we get host JDK Class objects // and that just doesn't work). try { - jnodeType = VmType.getObjectClass().getLoader().loadClass(name.classNameFromDescriptor(), false); + jnodeType = VmType.getObjectClass().getLoader().loadClass(name.classNameFromDescriptor(), true); } catch (Exception e) { e.printStackTrace(); return null; Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_BURS_Helpers.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_BURS_Helpers.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_BURS_Helpers.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -222,7 +222,7 @@ if(VM.BuildForJNode) { OPT_RegisterOperand eax = new OPT_RegisterOperand(burs.ir.regpool.getPhysicalRegisterSet().getEAX(), VM_TypeReference.ObjectReference); - EMIT(MIR_Move.mutate(s, IA32_MOV, obj, eax)); + EMIT(MIR_Move.mutate(s, IA32_MOV, eax, obj)); } else { int offset = - burs.ir.stackManager. allocateSpaceForCaughtException(); @@ -1867,13 +1867,15 @@ VM_Class decl = null; //Make JTOC register - jtoc = regpool.makeTempInt(); - EMIT(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc.asRegister())); + jtoc = new OPT_RegisterOperand(regpool.getPhysicalRegisterSet().getPR(), VM_TypeReference.Address); + //EMIT(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc.asRegister())); OPT_Operand memberOp = s.getOperand(0); //Get the declaring class for the field/method requiring resolution if(memberOp instanceof OPT_MethodOperand) decl = ((OPT_MethodOperand)memberOp).getTarget().getDeclaringClass(); + else if (memberOp instanceof OPT_TypeOperand) + decl = ((OPT_TypeOperand)memberOp).getVMType().asClass(); else decl = ((OPT_LocationOperand)memberOp).getFieldRef().peekResolvedMember().getDeclaringClass(); @@ -1886,8 +1888,8 @@ Offset.fromIntSignExtend(jtocOffset), (byte)BYTES_IN_ADDRESS, null, null))); //Call class resolver - jtoc = regpool.makeTempInt(); - EMIT(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc.asRegister().copyRO())); + jtoc = new OPT_RegisterOperand(regpool.getPhysicalRegisterSet().getPR(), VM_TypeReference.Address); + //EMIT(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc.asRegister().copyRO())); OPT_Operand target = OPT_MemoryOperand.BD(jtoc.asRegister().copyRO(), VM_Magic.getVmTypeInitialize().getOffset(), (byte)BYTES_IN_ADDRESS, null, null); EMIT(MIR_Call.mutate1(s, IA32_CALL, null, null, target, classr.copy())); Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_ClassLoaderProxy.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_ClassLoaderProxy.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_ClassLoaderProxy.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -281,8 +281,7 @@ */ public static OPT_IntConstantOperand getIntFromConstantPool (VM_Class klass, int index) { - Offset offset = klass.getLiteralOffset(index) ; - int val = VM_Statics.getSlotContentsAsInt(offset); + int val = klass.getIntLiteral(index); return new OPT_IntConstantOperand(val); } @@ -292,10 +291,8 @@ */ public static OPT_DoubleConstantOperand getDoubleFromConstantPool (VM_Class klass, int index) { - Offset offset = klass.getLiteralOffset(index) ; - long val_raw = VM_Statics.getSlotContentsAsLong(offset); - double val = Double.longBitsToDouble(val_raw); - return new OPT_DoubleConstantOperand(val, offset); + double val = klass.getDoubleLiteral(index); + return new OPT_DoubleConstantOperand(val); } /** @@ -304,10 +301,8 @@ */ public static OPT_FloatConstantOperand getFloatFromConstantPool (VM_Class klass, int index) { - Offset offset = klass.getLiteralOffset(index) ; - int val_raw = VM_Statics.getSlotContentsAsInt(offset); - float val = Float.intBitsToFloat(val_raw); - return new OPT_FloatConstantOperand(val, offset); + float val = klass.getFloatLiteral(index); + return new OPT_FloatConstantOperand(val); } /** @@ -316,9 +311,8 @@ */ public static OPT_LongConstantOperand getLongFromConstantPool (VM_Class klass, int index) { - Offset offset = klass.getLiteralOffset(index) ; - long val = VM_Statics.getSlotContentsAsLong(offset); - return new OPT_LongConstantOperand(val, offset); + long val = klass.getLongLiteral(index); + return new OPT_LongConstantOperand(val); } /** @@ -327,23 +321,7 @@ */ public static OPT_StringConstantOperand getStringFromConstantPool (VM_Class klass, int index) { Offset offset = klass.getLiteralOffset(index); - String val; - if (VM.runningVM) { - val = (String)VM_Statics.getSlotContentsAsObject(offset); - } else { - // Sigh. What we really want to do is acquire the - // String object from the class constant pool. - // But, we aren't set up to do that. The following - // isn't strictly correct, but is closer than the completely bogus - // thing we were doing before. - // TODO: Fix this to do the right thing. - // This will be wrong if someone is comparing string constants - // using ==, != since we're very unlikely to get the aliasing right. - // Then again, if you are using ==, != with strings and one of them - // isn't <null>, perhaps you deserve what you get. - // This is defect 2838. - val = ("BootImageStringConstant "+VM_Statics.offsetAsSlot(offset)).intern(); - } + String val = klass.getStringLiteral(index); return new OPT_StringConstantOperand(val, offset); } @@ -352,8 +330,7 @@ * pool. */ public static OPT_ClassConstantOperand getClassFromConstantPool (VM_Class klass, int index) { - Offset offset = klass.getLiteralOffset(index); VM_TypeReference val = klass.getTypeRef(index); - return new OPT_ClassConstantOperand(val, offset); + return new OPT_ClassConstantOperand(val); } } Modified: branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_DynamicTypeCheckExpansion.java =================================================================== --- branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_DynamicTypeCheckExpansion.java 2007-01-16 23:17:32 UTC (rev 3081) +++ branches/jikesRVM/core/src/core/com/ibm/JikesRVM/opt/OPT_DynamicTypeCheckExpansion.java 2007-01-16 23:20:01 UTC (rev 3082) @@ -7,6 +7,7 @@ import com.ibm.JikesRVM.*; import com.ibm.JikesRVM.classloader.*; import com.ibm.JikesRVM.opt.ir.*; + import org.vmmagic.unboxed.*; /** * Expansion of Dynamic Type Checking operations. @@ -537,9 +538,10 @@ OPT_RegisterOperand RHStib, OPT_RegisterOperand result) { // Is LHStype a class? - if (LHStype.isClassType()) { + if (LHStype.isClassType() + && !(VM.BuildForJNode && LHStype.peekResolvedType().isInterface())) { VM_Class LHSclass = (VM_Class)LHStype.peekResolvedType(); - if (LHSclass != null && LHSclass.isResolved()) { + if (LHSclass != null) { // Cases 4, 5, and 6 of VM_DynamicTypeCheck: LHSclass is a // resolved class or interface if (LHSclass.isInterface()) { @@ -594,7 +596,11 @@ int LHSDepth = LHSclass.getTypeDepth(); int LHSId = LHSclass.getId(); OPT_RegisterOperand superclassIds; + OPT_Operand classTIB = null; if(VM.BuildForJNode) { + if(s.getOpcode()==INSTANCEOF_UNRESOLVED_opcode) { + classTIB = resolveJnodeClass(LHSclass, s, ir); + } superclassIds = InsertUnary(s, ir, GET_SUPERCLASS_IDS_FROM_TIB, VM_TypeReference.IntArray, RHStib); @@ -607,14 +613,16 @@ } OPT_RegisterOperand refCandidate = null; if(VM.BuildForJNode) { - refCandidate = + if(s.getOpcode()!=INSTANCEOF_UNRESOLVED_opcode) { + classTIB = getTIB(s, ir, LHSclass); + } + refCandidate = InsertLoadOffset(s, ir, INT_LOAD, VM_TypeReference.Int, superclassIds, Offset.fromIntZeroExtend( (LHSDepth << LOG_BYTES_IN_ADDRESS) +VM_ObjectModel.ARRAY_DATA_OFFSET.toInt()), new OPT_LocationOperand(VM_TypeReference.Int), TG()); - OPT_Operand classTIB = getTIB(s, ir, LHSclass); s.insertBefore(BooleanCmp.create(BOOLEAN_CMP_ADDR, result, refCandidate, classTIB, @@ -665,11 +673,12 @@ return callHelper(s, ir); } } - if (LHStype.isArrayType()) { + if (LHStype.isArrayType() + || (VM.BuildForJNode && LHStype.peekResolvedType().isInterface())) { // Case 2 of VM_DynamicTypeCheck: LHS is an array. - VM_Array LHSArray = (VM_Array)LHStype.peekResolvedType(); - if (LHSArray != null) { - VM_Type innermostElementType = LHSArray.getInnermostElementType(); + VM_Type LHSArray = LHStype.peekResolvedType(); + if (LHSArray != null && LHStype.isArrayType()) { + VM_Type innermostElementType = ((VM_Array)LHSArray).getInnermostElementType(); if (innermostElementType.isPrimitiveType() || (innermostElementType.asClass().isResolved() && innermostElementType.asClass().isFinal())) { @@ -763,9 +772,10 @@ s.insertBefore(continueAt); s.remove(); - if (LHStype.isClassType()) { + if (LHStype.isClassType() + && !(VM.BuildForJNode && LHStype.peekResolvedType().isInterface())) { VM_Class LHSclass = (VM_Class)LHStype.peekResolvedType(); - if (LHSclass != null && LHSclass.isResolved()) { + if (LHSclass != null) { // Cases 4, 5, and 6 of VM_DynamicTypeCheck: LHSclass is a resolved // class or interface if (LHSclass.isInterface()) { @@ -823,8 +833,12 @@ int LHSDepth = LHSclass.getTypeDepth(); int LHSId = LHSclass.getId(); OPT_RegisterOperand superclassIds; + OPT_RegisterOperand cls = null; if(VM.BuildForJNode) { - superclassIds = + if(s.getOpcode()==INSTANCEOF_UNRESOLVED_opcode) { + cls = resolveJnodeClass(LHSclass, continueAt, ir); + } + superclassIds = InsertUnary(continueAt, ir, GET_SUPERCLASS_IDS_FROM_TIB, VM_TypeReference.IntArray, RHStib); } @@ -852,25 +866,26 @@ } OPT_Operand cmpWith; OPT_LocationOperand loc; - OPT_RegisterOperand refCandidate; Offset supOffset; + OPT_RegisterOperand refCandidate = null; if(VM.BuildForJNode) { cmpWith = ir.regpool.makeTempInt(); OPT_RegisterOperand jtoc = ir.regpool.makeTempInt(); - Offset clsOffset = LHSclass.getTibOffset(); + loc = new OPT_LocationOperand(VM_TypeReference.Int); supOffset = Offset.fromIntZeroExtend(LHSDepth << LOG_BYTES_IN_INT) - .add(VM_ObjectModel.getArrayDataOffset()); - loc = new OPT_LocationOperand(VM_TypeReference.Int); - continueAt.insertBefore(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc)); - OPT_RegisterOperand cls = InsertLoadOffset(continueAt, ir, INT_LOAD, VM_TypeReference.Int, - jtoc, clsOffset, loc, TG()); + .add(VM_ObjectModel.getArrayDataOffset()); + if(s.getOpcode()!=INSTANCEOF_UNRESOLVED_opcode) { + Offset clsOffset = LHSclass.getTibOffset(); + continueAt.insertBefore(JnodeMagic.create(JNODE_SHARED_STATICS, jtoc)); + cls = InsertLoadOffset(continueAt, ir, INT_LOAD, VM_TypeReference.Int, + jtoc, clsOffset, loc, TG()); + } continueAt.insertBefore(Move.create(INT_MOVE, cmpWith.asRegister(), cls)); - - refCandidate = - InsertLoadOffset(continueAt, ir, INT_LOAD, VM_TypeReference.Int, - superclassIds, supOffset, - new OPT_LocationOperand(VM_TypeReference.Int), - TG()); + refCandidate = + InsertLoadOffset(continueAt, ir, INT_LOAD, VM_TypeReference.Int, + superclassIds, supOffset, + new OPT_LocationOperand(VM_TypeReference.Int), + TG()); } else { cmpWith = IC(LHSId); @@ -883,7 +898,7 @@ TG()); } continueAt.insertBefore(IfCmp.create(INT_IFCMP, oldGuard, - refCandidate, cmpWith, + refCandidate, cmpWith.copy(), OPT_ConditionOperand.NOT_EQUAL(), falseBlock.makeJumpTarget(), falseProb)); @@ -911,71 +926,137 @@ } } - if (LHStype.isArrayType()) { + if (LHStype.isArrayType() + || (VM.BuildForJNode && LHStype.peekResolvedType().isInterface())) { // Case 2 of VM_DynamicTypeCheck: LHS is an array. - VM_Array LHSArray = (VM_Array)LHStype.peekResolvedType(); + VM_Type LHSArray = LHStype.peekResolvedType(); if (LHSArray != null) { OPT_Operand classTIB = getTIB(continueAt, ir, LHSArray); - VM_Type innermostElementType = LHSArray.getInnermostElementType(); - if (innermostElementType.isPrimitiveType() || - (innermostElementType.asClass().isResolved() && - innermostElementType.asClass().isFinal())) { - // [^k of primitive or [^k of final class. Just like final classes, - // a PTR compare of rhsTIB and the TIB of the class gives the answer. - continueAt.insertBefore(IfCmp.create(REF_IFCMP, oldGuard, - RHStib, classTIB, - OPT_ConditionOperand.NOT_EQUAL(), - falseBlock.makeJumpTarget(), - falseProb)); - return continueAt; + if(LHStype.isArrayType()) { + VM_Type innermostElementType = ((VM_Array)LHSArray).getInnermostElementType(); + if (innermostElementType.isPrimitiveType() || + (innermostElementType.asClass().isResolved() && + innermostElementType.asClass().isFinal())) { + // [^k of primitive or [^k of final class. Just like final classes, + // a PTR compare of rhsTIB and the TIB of the class gives the answer. + continueAt.insertBefore(IfCmp.create(REF_IFCMP, oldGuard, + RHStib, classTIB, + OPT_ConditionOperand.NOT_EQUAL(), + falseBlock.makeJumpTarget(), + falseProb)); + return continueAt; + } } - // TODO: branch probability calculation is somewhat bogus for this case. - OPT_Instruction shortcircuit = - IfCmp.create(REF_IFCMP, oldGuard, RHStib, classTIB, - OPT_ConditionOperand.EQUAL(), - trueBlock.makeJumpTarget(), - new OPT_BranchProfileOperand()); - if (oldGuard != null) - oldGuard = oldGuard.copyD2D(); - continueAt.insertBefore(shortcircuit); - OPT_BasicBlock myBlock = shortcircuit.getBasicBlock(); - OPT_BasicBlock mainBlock = - myBlock.splitNodeWithLinksAt(shortcircuit, ir); - myBlock.insertOut(trueBlock); // must come after the splitNodeAt - OPT_RegisterOperand rhsType = - InsertUnary(continueAt, ir, GET_TYPE_FROM_TIB, - VM_TypeReference.VM_Type, RHStib.copyD2U()); - if (innermostElementType.isJavaLangObjectType()) { - OPT_IntConstantOperand lhsDimension = IC(LHStype.getDimensionality()); - OPT_RegisterOperand rhsDimension = - getField(continueAt, ir, rhsType, VM_Entrypoints.dimensionField); - OPT_Instruction dimTest = - IfCmp2.create(INT_IFCMP2, oldGuard, rhsDimension, lhsDimension, - OPT_ConditionOperand.GREATER(), - trueBlock.makeJumpTarget(), - ((OPT_BranchProfileOperand)falseProb.copy()).flip(), - OPT_ConditionOperand.LESS(), - falseBlock.makeJumpTarget(), - (OPT_BranchProfileOperand)falseProb.copy()); - if (oldGuard != null) - oldGuard = oldGuard.copyD2D(); - continueAt.insertBefore(dimTest); - OPT_BasicBlock testBlock = - mainBlock.splitNodeWithLinksAt(dimTest, ir); - mainBlock.insertOut(trueBlock); - mainBlock.insertOut(falseBlock); - OPT_RegisterOperand rhsInnermostElementType = - getField(continueAt,ir,rhsType.copyU2U(),VM_Entrypoints.innermostElementTypeField); - OPT_RegisterOperand rhsInnermostElementTypeDimension = - getField(continueAt, ir, rhsInnermostElementType, VM_Entrypoints.dimensionField); - continueAt.insertBefore(IfCmp.create(INT_IFCMP, oldGuard, - rhsInnermostElementTypeDimension, - IC(0), - OPT_ConditionOperand.NOT_EQUAL(), - falseBlock.makeJumpTarget(), - falseProb)); - return continueAt; + if(VM.BuildForJNode) { + OPT_RegisterOperand superclassIds = + InsertUnary(continueAt, ir, GET_SUPERCLASS_IDS_FROM_TIB, + VM_TypeReference.IntArray, RHStib.copy()); + OPT_RegisterOperand superclassIdsLength = + InsertGuardedUnary(continueAt, + ir, ARRAYLENGTH, VM_TypeReference.Int, + superclassIds, TG()); + + //------------------Begin loop---------------------------// + OPT_BasicBlock oldBlock = continueAt.getBasicBlock(); + OPT_BasicBlock loopBlock = oldBlock.splitNodeWithLinksAt(continueAt.prevInstructionInCodeOrder(), ir); + + OPT_RegisterOperand temp = ir.regpool.makeTempInt(); + OPT_RegisterOperand lastSuperClassAddr = ir.regpool.makeTempInt(); + OPT_RegisterOperand currentSuperClass = ir.regpool.makeTempInt(); + + continueAt.insertBefore(Binary.create(INT_MUL, temp, + superclassIdsLength.copy(), IC(BYTES_IN_INT))); + + continueAt.insertBefore(Binary.create(INT_ADD, lastSuperClassAddr, + temp.copy(), IC(VM_Array.DATA_OFFSET*BYTES_IN_INT))); + + continueAt.insertBefore(Load.create(INT_LOAD, + currentSuperClass, superclassIds.copy(), lastSuperClassAddr, null)); + + continueAt.insertBefore(IfCmp.create(REF_IFCMP, oldGuard, + currentSuperClass.copy(), classTIB, + OPT_ConditionOperand.EQUAL(), + trueBlock.makeJumpTarget(), + new OPT_BranchProfileOperand())); + + continueAt.insertBefore(Binary.create(INT_SUB, temp.copyRO(), + temp.copy(), IC(BYTES_IN_ADDRESS))); + + continueAt.insertBefore(Binary.create(INT_SUB, superclassIdsLength.copyRO(), + superclassIdsLength.copy(), IC(1))); + + continueAt.insertBefore(IfCmp.create(INT_IFCMP, oldGuard, + superclassIdsLength.copy(), IC(0), + OPT_ConditionOperand.EQUAL(), + falseBlock.makeJumpTarget(), + (OPT_BranchProfileOperand)falseProb.copy())); + continueAt.insertBefore(IfCmp.create(INT_IFCMP, oldGuard, + superclassIdsLength.copy(), IC(0), + OPT_ConditionOperand.NOT_EQUAL(), + loopBlock.makeJumpTarget(), + (OPT_BranchProfileOperand)falseProb.copy())); + //continueAt.insertBefore(Goto.create(GOTO, loopBlock.makeJumpTarget())); + //Goto.mutate(continueAt, GOTO, trueBlock.makeJumpTarget()); + continueAt.remove(); + + + loopBlock.insertOut(trueBlock); + loopBlock.insertOut(falseBlock); + loopBlock.insertOut(loopBlock); + return loopBlock.lastRealInstruction();//continueAt; + + } + else { + VM_Type innermostElementType = ((VM_Array)LHSArray).getInnermostElementType(); + // TODO: branch probability calculation is somewhat bogus for this case. + OPT_Instruction shortcircuit = + IfCmp.create(REF_IFCMP, oldGuard, RHStib, classTIB, + OPT_ConditionOperand.EQUAL(), + trueBlock.makeJumpTarget(), + new OPT_BranchProfileOperand()); + if (oldGuard != null) + oldGuard = oldGuard.copyD2D(); + continueAt.insertBefore(shortcircuit); + OPT_BasicBlock myBlock = shortcircuit.getBasicBlock(); + OPT_BasicBlock mainBlock = + myBlock.splitNodeWithLinksAt(shortcircuit, ir); + myBlock.insertOut(trueBlock); // must come after the splitNodeAt + OPT_RegisterOperand rhsType = + InsertUnary(continueAt, ir, GET_TYPE_FROM_TIB, + VM_TypeReference.VM_Type, RHStib.copyD2U()); + if (innermostElementType.isJavaLangObjectType()) { + OPT_IntConstantOperand lhsDimension = IC(LHStype.getDimensionality()); + OPT_RegisterOperand rhsDimension = + getField(continueAt, ir, rhsType, VM_Entrypoints.dimensionField); + OPT_Instruction dimTest = + IfCmp2.create(INT_IFCMP2, oldGuard, rhsDimension, lhsDimension, + OPT_ConditionOperand.GREATER(), + trueBlock.makeJumpTarget(), + ((OPT_BranchProfileOperand)falseProb.copy()).flip(), + OPT_ConditionOperand.LESS(), + falseBlock.makeJumpTarget(), + (OPT_BranchProfileOperand)falseProb.copy()); + if (oldGuard != null) + oldGuard = oldGuard.copyD2D(); + continueAt.insertBefore(dimTest); + OPT_BasicBlock testBlock = + mainBlock.splitNodeWithLinksAt(dimTest, ir); + mainBlock.insertOut(trueBlock); + mainBlock.insertOut(falseBlock); + OPT_RegisterOperand rhsInnermostElementType = + getField(continueAt,ir,rhsType.copyU2U(),VM_Entrypoints.innermostElementTypeField); + OPT_RegisterOperand rhsInnermostElementTypeDimension = + getField(continueAt, ir, rhsInnermostElementType, VM_Entrypoints.dimensionField); + continueAt.insertBefore(IfCmp.create(INT_IFCMP, oldGuard, + rhsInnermostElementTypeDimension, + IC(0), + OPT_ConditionOperand.NOT_EQUAL(), + falseBlock.makeJumpTarget(... [truncated message content] |
From: <ans...@us...> - 2007-01-16 23:17:34
|
Revision: 3081 http://jnode.svn.sourceforge.net/jnode/?rev=3081&view=rev Author: ansari82 Date: 2007-01-16 15:17:32 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Made methods that use Unsafe.pushxxx() set to NoOptCompile as this can confuse JikesOpt generated code Modified Paths: -------------- branches/jikesRVM/core/src/core/org/jnode/vm/HeapHelperImpl.java branches/jikesRVM/core/src/core/org/jnode/vm/VmReflection.java branches/jikesRVM/core/src/core/org/jnode/vm/VmSystemClassLoader.java branches/jikesRVM/core/src/core/org/jnode/vm/compiler/CompiledMethod.java Modified: branches/jikesRVM/core/src/core/org/jnode/vm/HeapHelperImpl.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/HeapHelperImpl.java 2007-01-16 23:16:49 UTC (rev 3080) +++ branches/jikesRVM/core/src/core/org/jnode/vm/HeapHelperImpl.java 2007-01-16 23:17:32 UTC (rev 3081) @@ -22,6 +22,7 @@ package org.jnode.vm; import org.jnode.vm.annotation.MagicPermission; +import org.jnode.vm.annotation.NoOptCompile; import org.jnode.vm.annotation.Uninterruptible; import org.jnode.vm.classmgr.ObjectFlags; import org.jnode.vm.classmgr.ObjectLayout; @@ -199,6 +200,7 @@ * @see org.jnode.vm.memmgr.HeapHelper#invokeFinalizer(org.jnode.vm.classmgr.VmMethod, * java.lang.Object) */ + @NoOptCompile //Uses Unsafe.pushxxx() which is bad for JikesOpt public final void invokeFinalizer(VmMethod finalizer, Object object) { Unsafe.pushObject(object); Unsafe.invokeVoid(finalizer); Modified: branches/jikesRVM/core/src/core/org/jnode/vm/VmReflection.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/VmReflection.java 2007-01-16 23:16:49 UTC (rev 3080) +++ branches/jikesRVM/core/src/core/org/jnode/vm/VmReflection.java 2007-01-16 23:17:32 UTC (rev 3081) @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; import org.jnode.vm.annotation.MagicPermission; +import org.jnode.vm.annotation.NoOptCompile; import org.jnode.vm.classmgr.VmField; import org.jnode.vm.classmgr.VmInstanceField; import org.jnode.vm.classmgr.VmMethod; @@ -309,6 +310,7 @@ * @return Object * @throws InvocationTargetException */ + @NoOptCompile //Uses Unsafe.pushxxx() which is bad for JikesOpt public static Object invoke(VmMethod method, Object o, Object[] args) throws InvocationTargetException { int argCount = method.getNoArguments(); @@ -440,6 +442,7 @@ * @throws IllegalAccessException * @throws InvocationTargetException */ + @NoOptCompile //Uses Unsafe.pushxxx() which is bad for JikesOpt public static Object newInstance(VmMethod constructor) throws InstantiationException, IllegalAccessException, InvocationTargetException { Modified: branches/jikesRVM/core/src/core/org/jnode/vm/VmSystemClassLoader.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/VmSystemClassLoader.java 2007-01-16 23:16:49 UTC (rev 3080) +++ branches/jikesRVM/core/src/core/org/jnode/vm/VmSystemClassLoader.java 2007-01-16 23:17:32 UTC (rev 3081) @@ -297,8 +297,7 @@ @PrivilegedActionPragma public VmType< ? > loadClass(String name, boolean resolve) throws ClassNotFoundException { - - // Also implement the java.lang.ClassLoader principals here +// Also implement the java.lang.ClassLoader principals here // otherwise they cannot work in java.lang.ClassLoader. if ((parent != null) && !parent.skipParentLoader(name)) { try { @@ -308,7 +307,6 @@ // Don't care, try it ourselves. } } - VmType cls = findLoadedClass(name); if (cls != null) { return cls; @@ -316,11 +314,7 @@ if (classInfos == null) { // Unsafe.debug("classInfos==null"); throw new ClassNotFoundException(name); - } - - // BootLog.debug("load class" + name); - - if (name.indexOf('/') >= 0) { + }if (name.indexOf('/') >= 0) { //throw new IllegalArgumentException("name contains '/'"); //throw CNFE here throw new ClassNotFoundException(name); @@ -329,39 +323,53 @@ if ((failedClassNames != null) && (failedClassNames.contains(name))) { throw new ClassNotFoundException(name); } - + final ClassInfo ci = getClassInfo(name, true); - + if (!ci.isLoaded()) { - try { - if (name.charAt(0) == '[') { - ci.setVmClass(loadArrayClass(name, resolve)); - } else { - ci.setVmClass(loadNormalClass(name)); + if (name.charAt(0) == '[') { + try { + ci.setVmClass(loadArrayClass(name, resolve)); + if (failOnNewLoad) { + throw new RuntimeException( + "Cannot load a new class when failOnNewLoad is set (" + + name + ")"); + } + }catch (ClassNotFoundException ex) { + ci.setLoadError(ex.toString()); + classInfos.remove(ci.getName()); + addFailedClassName(name); + throw new ClassNotFoundException(name, ex); } - if (failOnNewLoad) { - throw new RuntimeException( - "Cannot load a new class when failOnNewLoad is set (" - + name + ")"); - } - } catch (ClassNotFoundException ex) { - ci.setLoadError(ex.toString()); - classInfos.remove(ci.getName()); - addFailedClassName(name); - throw new ClassNotFoundException(name, ex); - } catch (IOException ex) { - ci.setLoadError(ex.toString()); - classInfos.remove(ci.getName()); - addFailedClassName(name); - throw new ClassNotFoundException(name, ex); + } else { + try { + ci.setVmClass(loadNormalClass(name)); + if (failOnNewLoad) { + throw new RuntimeException( + "Cannot load a new class when failOnNewLoad is set (" + + name + ")"); + } + } catch (ClassNotFoundException ex) { + ci.setLoadError(ex.toString()); + classInfos.remove(ci.getName()); + addFailedClassName(name); + throw new ClassNotFoundException(name, ex); + } catch (IOException ex) { + ci.setLoadError(ex.toString()); + classInfos.remove(ci.getName()); + addFailedClassName(name); + throw new ClassNotFoundException(name, ex); + } } - if (resolve) { + if (resolve) { ci.getVmClass().link(); } } return ci.getVmClass(); } + + private final void addFailedClassName(String name) { if (failedClassNames == null) { failedClassNames = new HashSet<String>(); Modified: branches/jikesRVM/core/src/core/org/jnode/vm/compiler/CompiledMethod.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/compiler/CompiledMethod.java 2007-01-16 23:16:49 UTC (rev 3080) +++ branches/jikesRVM/core/src/core/org/jnode/vm/compiler/CompiledMethod.java 2007-01-16 23:17:32 UTC (rev 3081) @@ -31,7 +31,7 @@ /** * @author Ewout Prangsma (ep...@us...) */ -public final class CompiledMethod { +public class CompiledMethod { private NativeStream.ObjectRef codeStart; private NativeStream.ObjectRef codeEnd; @@ -40,7 +40,7 @@ private final VmAddressMap addressTable; private final int optLevel; private int ccId = -1; - private VM_CompiledMethod jikesCM; +// private VM_CompiledMethod jikesCM; /** * Initialize this instance @@ -147,11 +147,11 @@ return ccId; } - public VM_CompiledMethod getJikesCM() { - return jikesCM; - } - - public void setJikesCM(VM_CompiledMethod method) { - jikesCM = method; - } +// public VM_CompiledMethod getJikesCM() { +// return jikesCM; +// } +// +// public void setJikesCM(VM_CompiledMethod method) { +// jikesCM = method; +// } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:16:51
|
Revision: 3080 http://jnode.svn.sourceforge.net/jnode/?rev=3080&view=rev Author: ansari82 Date: 2007-01-16 15:16:49 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Modified LoadCompileService to check for NoOptCompile, and use previous compiler if this is set and the JikesOpt compiler has been selected (this can be done better, e.g. by explicitly defining a fallback compiler, since the 'previous' compiler may be null, arrayoutofbounds, or stub Modified Paths: -------------- branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java Modified: branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-16 23:14:51 UTC (rev 3079) +++ branches/jikesRVM/core/src/core/org/jnode/vm/LoadCompileService.java 2007-01-16 23:16:49 UTC (rev 3080) @@ -208,7 +208,8 @@ } if (vmMethod.getNativeCodeOptLevel() < optLevel) { if(cmps[index] instanceof JikesRVMOptCompiler && - !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test")) + !vmMethod.getDeclaringClass().getName().startsWith("org.jnode.test") + || vmMethod.hasNoOptCompilePragma()) cmp = cmps[index-1]; else cmp = cmps[index]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:14:52
|
Revision: 3079 http://jnode.svn.sourceforge.net/jnode/?rev=3079&view=rev Author: ansari82 Date: 2007-01-16 15:14:51 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Added support to allow methods to have NoOptCompile annotation set on them Modified Paths: -------------- branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/MethodPragmaFlags.java branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/VmMethod.java Modified: branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java 2007-01-16 23:13:48 UTC (rev 3078) +++ branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java 2007-01-16 23:14:51 UTC (rev 3079) @@ -38,6 +38,7 @@ import org.jnode.vm.annotation.MagicPermission; import org.jnode.vm.annotation.NoFieldAlignments; import org.jnode.vm.annotation.NoInline; +import org.jnode.vm.annotation.NoOptCompile; import org.jnode.vm.annotation.NoReadBarrier; import org.jnode.vm.annotation.NoWriteBarrier; import org.jnode.vm.annotation.PrivilegedActionPragma; @@ -118,7 +119,9 @@ new PragmaAnnotation(Uninterruptible.class, MethodPragmaFlags.UNINTERRUPTIBLE), new PragmaAnnotation(KernelSpace.class, - MethodPragmaFlags.KERNELSPACE), }; + MethodPragmaFlags.KERNELSPACE), + new PragmaAnnotation(NoOptCompile.class, + MethodPragmaFlags.NOOPTCOMPILE),}; /** * Names of classes that you use shared statics, but cannot be modified. Modified: branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/MethodPragmaFlags.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/MethodPragmaFlags.java 2007-01-16 23:13:48 UTC (rev 3078) +++ branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/MethodPragmaFlags.java 2007-01-16 23:14:51 UTC (rev 3079) @@ -59,4 +59,7 @@ /** Method is run in kernel space (ring 0) */ public static final char KERNELSPACE = 0x0200; + /** Method is run in kernel space (ring 0) */ + public static final char NOOPTCOMPILE = 0x0400; + } Modified: branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/VmMethod.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/VmMethod.java 2007-01-16 23:13:48 UTC (rev 3078) +++ branches/jikesRVM/core/src/core/org/jnode/vm/classmgr/VmMethod.java 2007-01-16 23:14:51 UTC (rev 3079) @@ -536,8 +536,16 @@ public final boolean hasKernelSpacePragma() { return ((pragmaFlags & MethodPragmaFlags.KERNELSPACE) != 0); } - + /** + * Is the NoOptCompile pragma set for this method. + * @return + */ + public final boolean hasNoOptCompilePragma() { + return ((pragmaFlags & MethodPragmaFlags.NOOPTCOMPILE) != 0); + } + + /** * Mark this method as uninterruptable. */ final void setUninterruptible() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:13:53
|
Revision: 3078 http://jnode.svn.sourceforge.net/jnode/?rev=3078&view=rev Author: ansari82 Date: 2007-01-16 15:13:48 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Added NoOptCompile pragma Added Paths: ----------- branches/jikesRVM/core/src/core/org/jnode/vm/annotation/NoOptCompile.java Added: branches/jikesRVM/core/src/core/org/jnode/vm/annotation/NoOptCompile.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/vm/annotation/NoOptCompile.java (rev 0) +++ branches/jikesRVM/core/src/core/org/jnode/vm/annotation/NoOptCompile.java 2007-01-16 23:13:48 UTC (rev 3078) @@ -0,0 +1,16 @@ +package org.jnode.vm.annotation; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Documented +@Retention(CLASS) +@Target({CONSTRUCTOR, METHOD}) +public @interface NoOptCompile { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-16 23:13:27
|
Revision: 3077 http://jnode.svn.sourceforge.net/jnode/?rev=3077&view=rev Author: ansari82 Date: 2007-01-16 15:13:24 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Fixed spelling Modified Paths: -------------- branches/jikesRVM/core/src/core/org/jnode/boot/Main.java Modified: branches/jikesRVM/core/src/core/org/jnode/boot/Main.java =================================================================== --- branches/jikesRVM/core/src/core/org/jnode/boot/Main.java 2007-01-15 13:33:17 UTC (rev 3076) +++ branches/jikesRVM/core/src/core/org/jnode/boot/Main.java 2007-01-16 23:13:24 UTC (rev 3077) @@ -91,9 +91,9 @@ final Method mainMethod = mainClass.getMethod("main", new Class[]{ String[].class}); mainMethod.invoke(null, new Object[]{proc.getMainClassArguments()}); } catch(NoSuchMethodException x) { - final Object insatnce = mainClass.newInstance(); - if(insatnce instanceof Runnable){ - ((Runnable) insatnce).run(); + final Object instance = mainClass.newInstance(); + if(instance instanceof Runnable){ + ((Runnable) instance).run(); } else { BootLog.warn("No valid Main-Class found"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hag...@us...> - 2007-01-15 13:33:20
|
Revision: 3076 http://jnode.svn.sourceforge.net/jnode/?rev=3076&view=rev Author: hagar-wize Date: 2007-01-15 05:33:17 -0800 (Mon, 15 Jan 2007) Log Message: ----------- removed a slash o sign from the date in the cvs log Modified Paths: -------------- trunk/core/src/core/org/jnode/debug/UDPAppender.java Modified: trunk/core/src/core/org/jnode/debug/UDPAppender.java =================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ans...@us...> - 2007-01-14 22:05:19
|
Revision: 3074 http://jnode.svn.sourceforge.net/jnode/?rev=3074&view=rev Author: ansari82 Date: 2007-01-14 09:06:45 -0800 (Sun, 14 Jan 2007) Log Message: ----------- Modified some native code so that it doesn't use ebx/esi, or saves them before use and restores them before returning, as these registers need to be left unmodified for jikes-compiled methods Modified Paths: -------------- branches/jikesRVM/core/src/native/x86/vm-ints.asm branches/jikesRVM/core/src/native/x86/vm.asm Modified: branches/jikesRVM/core/src/native/x86/vm-ints.asm =================================================================== --- branches/jikesRVM/core/src/native/x86/vm-ints.asm 2007-01-11 19:32:27 UTC (rev 3073) +++ branches/jikesRVM/core/src/native/x86/vm-ints.asm 2007-01-14 17:06:45 UTC (rev 3074) @@ -66,6 +66,8 @@ ; Usage: SAVE_MSR_ARRAY array-ref ; array-ref a reference to an MSR[]. Can be null. %macro SAVE_MSR_ARRAY 1 + push ebx + push esi mov ASI,%1 test ASI,ASI jnz %%save ; Arranged this way to optimize branch prediction @@ -85,14 +87,18 @@ ; Go to next position lea ASI,[ASI+SLOT_SIZE] dec ebx - jnz %%loop + jnz %%loop %%end: + pop esi + pop ebx %endmacro ; Restore an array of MSR's ; Usage: RESTORE_MSR_ARRAY array-ref ; array-ref a reference to an MSR[]. Can be null. %macro RESTORE_MSR_ARRAY 1 + push ebx + push esi mov ASI,%1 test ASI,ASI jnz %%restore ; Arranged this way to optimize branch prediction @@ -112,7 +118,9 @@ lea ASI,[ASI+SLOT_SIZE] dec ebx jnz %%loop -%%end: +%%end: + pop esi + pop ebx %endmacro yieldPointHandler_kernelCode: @@ -170,16 +178,16 @@ and dword [ADI+VmX86Thread_FXFLAGS_OFS],~VmX86Thread_FXF_USED ; Load fxStatePtr yieldPointHandler_loadFxStatePtr: - mov ABX, [ADI+VmX86Thread_FXSTATEPTR_OFS] - test ABX,ABX + mov ACX, [ADI+VmX86Thread_FXSTATEPTR_OFS] + test ACX,ACX jz near yieldPointHandler_fxSaveInit ; We have a valid fxState address in ebx test dword [cpu_features],FEAT_FXSR jz yieldPointHandler_fpuSave - fxsave [ABX] + fxsave [ACX] jmp yieldPointHandler_saveEnd yieldPointHandler_fpuSave: - fnsave [ABX] + fnsave [ACX] yieldPointHandler_saveEnd: ; Now call VmScheduler.reschedule (in kernel mode!) @@ -242,14 +250,14 @@ ; Set the new thread parameters mov CURRENTTHREAD,ADI ; Set the isolatedStatics of the new thread - mov ABX,[ADI+VmThread_ISOLATEDSTATICS_OFS] - mov ISOLATEDSTATICS,ABX + mov ACX,[ADI+VmThread_ISOLATEDSTATICS_OFS] + mov ISOLATEDSTATICS,ACX ; Set the isolatedStaticsTable of the new thread - mov ABX,[ABX+VmStatics_STATICS_OFS] - mov ISOLATEDSTATICSTABLE,ABX + mov ACX,[ACX+VmStatics_STATICS_OFS] + mov ISOLATEDSTATICSTABLE,ACX ; Reload stackend - mov ABX,[ADI+VmThread_STACKEND_OFS] - mov STACKEND,ABX + mov ACX,[ADI+VmThread_STACKEND_OFS] + mov STACKEND,ACX yieldPointHandler_done: and THREADSWITCHINDICATOR,~VmProcessor_TSI_SWITCH_ACTIVE ret @@ -271,10 +279,10 @@ ; Set the fxStatePtr in the thread given in edi. ; The fxStatePtr must be 16-byte aligned fixFxStatePtr: - mov ABX,[ADI+VmX86Thread_FXSTATE_OFS] - add ABX,(VmArray_DATA_OFFSET*SLOT_SIZE) + 15 - and ABX,~0xF; - mov [ADI+VmX86Thread_FXSTATEPTR_OFS],ABX + mov ACX,[ADI+VmX86Thread_FXSTATE_OFS] + add ACX,(VmArray_DATA_OFFSET*SLOT_SIZE) + 15 + and ACX,~0xF; + mov [ADI+VmX86Thread_FXSTATEPTR_OFS],ACX ret yieldPointHandler_fxSaveInit: @@ -298,17 +306,17 @@ ; Clear CR0.TS clts ; Restore fx state (if any) - mov ABX, [ADI+VmX86Thread_FXSTATEPTR_OFS] - test ABX,ABX + mov ACX, [ADI+VmX86Thread_FXSTATEPTR_OFS] + test ACX,ACX jz int_dev_na_ret ; No valid fxStatePtr yet, do not restore ; Increment counter inc FXRESTORECOUNTER test dword [cpu_features],FEAT_FXSR jz int_dev_na_fpuRestore - fxrstor [ABX] + fxrstor [ACX] ret int_dev_na_fpuRestore: - frstor [ABX] + frstor [ACX] int_dev_na_ret: ret Modified: branches/jikesRVM/core/src/native/x86/vm.asm =================================================================== --- branches/jikesRVM/core/src/native/x86/vm.asm 2007-01-11 19:32:27 UTC (rev 3073) +++ branches/jikesRVM/core/src/native/x86/vm.asm 2007-01-14 17:06:45 UTC (rev 3074) @@ -60,16 +60,16 @@ mov AAX, vm_findThrowableHandler INVOKE_JAVA_METHOD ; eax now contains the handler address of the exception, move it to ebx - mov ABX,AAX + mov ACX,AAX pop ADX ; restore address pop AAX ; restore exception vm_athrow_deliver_compiled: - test ABX,ABX + test ACX,ACX jz vm_athrow_notrace_pop_eip ; Jump to the compiled exception handler - jmp ABX + jmp ACX vm_athrow_unhandled: cli This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-14 20:18:40
|
Revision: 3075 http://jnode.svn.sourceforge.net/jnode/?rev=3075&view=rev Author: lsantha Date: 2007-01-14 12:18:39 -0800 (Sun, 14 Jan 2007) Log Message: ----------- Fixed instance method lookup in invoke(), java.lang.reflect.Proxy works now. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/VmReflection.java Modified: trunk/core/src/core/org/jnode/vm/VmReflection.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmReflection.java 2007-01-14 17:06:45 UTC (rev 3074) +++ trunk/core/src/core/org/jnode/vm/VmReflection.java 2007-01-14 20:18:39 UTC (rev 3075) @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; import org.jnode.vm.annotation.MagicPermission; +import org.jnode.vm.annotation.PrivilegedActionPragma; import org.jnode.vm.classmgr.VmField; import org.jnode.vm.classmgr.VmInstanceField; import org.jnode.vm.classmgr.VmMethod; @@ -309,7 +310,8 @@ * @return Object * @throws InvocationTargetException */ - public static Object invoke(VmMethod method, Object o, Object[] args) + @PrivilegedActionPragma //todo verify this wrt. security implications + public static Object invoke(VmMethod method, Object o, Object[] args) throws InvocationTargetException { int argCount = method.getNoArguments(); int argsLength = (args == null) ? 0 : args.length; @@ -321,7 +323,9 @@ if( o == null ) throw new NullPointerException(); Unsafe.pushObject(o); - } else { + if(!method.isConstructor()) + method = o.getClass().getVmClass().getMethod(method.getName(), method.getSignature()); + } else { method.getDeclaringClass().initialize(); } for (int i = 0; i < argCount; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-11 19:32:29
|
Revision: 3073 http://jnode.svn.sourceforge.net/jnode/?rev=3073&view=rev Author: lsantha Date: 2007-01-11 11:32:27 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Added support for transparency, based on a patch from Andrei Dore. Added Paths: ----------- trunk/gui/images/JNode_logo_trans.png Added: trunk/gui/images/JNode_logo_trans.png =================================================================== (Binary files differ) Property changes on: trunk/gui/images/JNode_logo_trans.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-11 19:30:50
|
Revision: 3072 http://jnode.svn.sourceforge.net/jnode/?rev=3072&view=rev Author: lsantha Date: 2007-01-11 11:30:49 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Added support for transparency, based on a patch from Andrei Dore. Modified Paths: -------------- trunk/gui/src/test/org/jnode/test/gui/SwingTest.java Modified: trunk/gui/src/test/org/jnode/test/gui/SwingTest.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/SwingTest.java 2007-01-11 19:30:25 UTC (rev 3071) +++ trunk/gui/src/test/org/jnode/test/gui/SwingTest.java 2007-01-11 19:30:49 UTC (rev 3072) @@ -23,9 +23,7 @@ import java.awt.BorderLayout; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JTextArea; +import javax.swing.*; /** * @author Ewout Prangsma (ep...@us...) @@ -40,7 +38,8 @@ getRootPane().setDoubleBuffered(false); setLocation(100, 100); setSize(400, 400); - getContentPane().add(north = new JButton("JButton north"), BorderLayout.NORTH); + //getContentPane().add(north = new JButton("JButton north"), BorderLayout.NORTH); + getContentPane().add(north = new JButton("JButton north",new ImageIcon(getClass().getClassLoader().getResource("JNode_logo_trans.png"))), BorderLayout.NORTH); getContentPane().add(new JTextArea("JTextArea test"), BorderLayout.CENTER); getContentPane().add(south = new JButton("JButton south"), BorderLayout.SOUTH); north.requestFocus(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-11 19:30:30
|
Revision: 3071 http://jnode.svn.sourceforge.net/jnode/?rev=3071&view=rev Author: lsantha Date: 2007-01-11 11:30:25 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Added support for transparency, based on a patch from Andrei Dore. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/VmSystem.java Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-01-11 19:29:39 UTC (rev 3070) +++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-01-11 19:30:25 UTC (rev 3071) @@ -262,6 +262,8 @@ res.put("gnu.classpath.home.url", "system://"); res.put("gnu.classpath.vm.shortname", "jnode"); res.put("gnu.javax.swing.noGraphics2D", "true"); + // keep this property until transparency support works fine with all drivers + res.put("org.jnode.awt.transparency", "true"); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-11 19:29:40
|
Revision: 3070 http://jnode.svn.sourceforge.net/jnode/?rev=3070&view=rev Author: lsantha Date: 2007-01-11 11:29:39 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Added support for transparency, based on a patch from Andrei Dore. Modified Paths: -------------- trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareConfiguration.java trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareCore.java Modified: trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareConfiguration.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareConfiguration.java 2007-01-11 19:29:15 UTC (rev 3069) +++ trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareConfiguration.java 2007-01-11 19:29:39 UTC (rev 3070) @@ -23,6 +23,7 @@ import java.awt.image.BufferedImage; import java.awt.image.ColorModel; +import java.awt.*; import org.jnode.driver.video.FrameBufferConfiguration; @@ -51,6 +52,10 @@ * @see java.awt.Transparency#TRANSLUCENT */ public BufferedImage createCompatibleImage(int w, int h, int transparency) { - return new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); - } + if(transparency == Transparency.TRANSLUCENT) + return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + else + //todo handle Transparency.BITMASK + return new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + } } Modified: trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareCore.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareCore.java 2007-01-11 19:29:15 UTC (rev 3069) +++ trunk/gui/src/driver/org/jnode/driver/video/vmware/VMWareCore.java 2007-01-11 19:29:39 UTC (rev 3070) @@ -52,6 +52,7 @@ import org.jnode.util.AccessControllerUtils; import org.jnode.util.NumberUtils; import org.vmmagic.unboxed.Address; +import gnu.classpath.SystemProperties; /** * @author epr @@ -74,9 +75,11 @@ private final int redMask; private final int greenMask; private final int blueMask; + private final int alphaMask; private final int redMaskShift; private final int greenMaskShift; private final int blueMaskShift; + private final int alphaMaskShift; private final int capabilities; private int bytesPerLine; private int offset; @@ -158,10 +161,18 @@ this.redMask = getReg32(SVGA_REG_RED_MASK); this.greenMask = getReg32(SVGA_REG_GREEN_MASK); this.blueMask = getReg32(SVGA_REG_BLUE_MASK); - this.redMaskShift = getMaskShift(redMask); + String transparency = SystemProperties.getProperty("org.jnode.awt.transparency"); + if(transparency != null && "true".equals(transparency)){ + //todo get this in the safe way + this.alphaMask = 0xff000000; // - transparency enabled + } else { + this.alphaMask = 0x00000000; // - transparency disabled + } + this.redMaskShift = getMaskShift(redMask); this.greenMaskShift = getMaskShift(greenMask); this.blueMaskShift = getMaskShift(blueMask); - } catch (NameNotFoundException ex) { + this.alphaMaskShift = getMaskShift(alphaMask); + } catch (NameNotFoundException ex) { throw new ResourceNotFreeException(ex); } } @@ -236,7 +247,7 @@ break; case 32 : { - bitmapGraphics = BitmapGraphics.create32bppInstance(videoRam, width, height, bytesPerLine, offset); + bitmapGraphics = BitmapGraphics.create32bppInstance(videoRam, width, height, bytesPerLine, offset, model.getTransparency()); } break; } @@ -244,8 +255,8 @@ } public FrameBufferConfiguration[] getConfigs() { - final ColorModel cm = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask); - return new FrameBufferConfiguration[] { + final ColorModel cm = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask, alphaMask); + return new FrameBufferConfiguration[] { new VMWareConfiguration(800, 600, cm), new VMWareConfiguration(1024, 768, cm), new VMWareConfiguration(1280, 1024, cm), @@ -595,8 +606,8 @@ * @param color */ protected final int convertColor(Color color) { - return convertColor(color.getRed(), color.getGreen(), color.getBlue()); - } + return convertColor(color.getRed(), color.getGreen(), color.getBlue(),color.getAlpha()); + } /** * Convert the given color to a value suitable for VMWare @@ -609,7 +620,11 @@ return ((r << redMaskShift) & redMask) | ((g << greenMaskShift) & greenMask) | ((b << blueMaskShift) & blueMask); } - /** + protected final int convertColor(int r, int g, int b,int a) { + return ((a << alphaMaskShift) & alphaMask) | ((r << redMaskShift) & redMask) | ((g << greenMaskShift) & greenMask) | ((b << blueMaskShift) & blueMask); + } + + /** * Gets the SVGA_ID of the VMware SVGA adapter. This function should hide any backward * compatibility mess. */ @@ -718,7 +733,8 @@ * @return */ private final int getMaskShift(int mask) { - int count = 0; + if(mask == 0) return 0; + int count = 0; while ((mask & 1) == 0) { count++; mask = mask >> 1; @@ -782,8 +798,8 @@ if (a != 0) { // opaque andMask[i] = 0; - xorMask[i] = v & convertColor(r, g, b); - } else { + xorMask[i] = v & convertColor(r, g, b,a); + } else { // transparent andMask[i] = 0xFFFFFFFF; xorMask[i] = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |