You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2008/11/26 20:02:17 UTC
svn commit: r720945 - in /xmlbeans/trunk/src:
store/org/apache/xmlbeans/impl/store/Locale.java
typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java
Author: cezar
Date: Wed Nov 26 11:02:16 2008
New Revision: 720945
URL: http://svn.apache.org/viewvc?rev=720945&view=rev
Log:
Fix deadlock when calling generated impl setters for singletons and array items.
Modified:
xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java
Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java?rev=720945&r1=720944&r2=720945&view=diff
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java Wed Nov 26 11:02:16 2008
@@ -3687,23 +3687,26 @@
private static final class DefaultQNameFactory
implements QNameFactory
{
- private QNameCache _cache = XmlBeans.getQNameCache();
+ private QNameCache getCache()
+ {
+ return XmlBeans.getQNameCache();
+ }
public QName getQName(String uri, String local)
{
- return _cache.getName(uri, local, "");
+ return getCache().getName(uri, local, "");
}
public QName getQName(String uri, String local, String prefix)
{
- return _cache.getName(uri, local, prefix);
+ return getCache().getName(uri, local, prefix);
}
public QName getQName(char[] uriSrc, int uriPos, int uriCch,
char[] localSrc, int localPos, int localCch)
{
return
- _cache.getName(new String(uriSrc, uriPos, uriCch),
+ getCache().getName(new String(uriSrc, uriPos, uriCch),
new String(localSrc, localPos, localCch),
"");
}
@@ -3713,7 +3716,7 @@
char[] prefixSrc, int prefixPos, int prefixCch)
{
return
- _cache.getName(new String(uriSrc, uriPos, uriCch),
+ getCache().getName(new String(uriSrc, uriPos, uriCch),
new String(localSrc, localPos, localCch),
new String(prefixSrc, prefixPos, prefixCch));
}
Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java?rev=720945&r1=720944&r2=720945&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java Wed Nov 26 11:02:16 2008
@@ -2210,12 +2210,30 @@
printJavaDoc((several ? "Sets first " : "Sets the ") + propdesc);
emit("public void set" + propertyName + "(" + type + " " + safeVarName + ")");
startBlock();
- emitImplementationPreamble();
- emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
- emitGetTarget(setIdentifier, identifier, isAttr, "0", ADD_NEW_VALUE, jtargetType);
- emit(jSet + "(" + safeVarName + ");");
- emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
- emitImplementationPostamble();
+ if ( xmltype )
+ {
+ emit("/*");
+ emitImplementationPreamble();
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ emitGetTarget(setIdentifier, identifier, isAttr, "0", ADD_NEW_VALUE, jtargetType);
+ emit(jSet + "(" + safeVarName + ");");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ emitImplementationPostamble();
+ emit("*/");
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ emit("generatedSetterHelperImpl(" + safeVarName + ", " + setIdentifier + ", 0, " +
+ "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_SINGLETON);");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ }
+ else
+ {
+ emitImplementationPreamble();
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ emitGetTarget(setIdentifier, identifier, isAttr, "0", ADD_NEW_VALUE, jtargetType);
+ emit(jSet + "(" + safeVarName + ");");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
+ emitImplementationPostamble();
+ }
endBlock();
if (!xmltype)
@@ -2314,12 +2332,30 @@
printJavaDoc("Sets ith " + propdesc);
emit("public void set" + arrayName + "(int i, " + type + " " + safeVarName + ")");
startBlock();
- emitImplementationPreamble();
- emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
- emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, jtargetType);
- emit(jSet + "(" + safeVarName + ");");
- emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
- emitImplementationPostamble();
+ if (javaType == SchemaProperty.XML_OBJECT)
+ {
+ emit("/*");
+ emitImplementationPreamble();
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, jtargetType);
+ emit(jSet + "(" + safeVarName + ");");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ emitImplementationPostamble();
+ emit("*/");
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ emit("generatedSetterHelperImpl(" + safeVarName + ", " + setIdentifier + ", i, " +
+ "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_ARRAYITEM);");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ }
+ else
+ {
+ emitImplementationPreamble();
+ emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, jtargetType);
+ emit(jSet + "(" + safeVarName + ");");
+ emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, "i");
+ emitImplementationPostamble();
+ }
endBlock();
if (!xmltype)
Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java?rev=720945&r1=720944&r2=720945&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java Wed Nov 26 11:02:16 2008
@@ -89,6 +89,10 @@
public static final short MAJOR_VERSION_NUMBER = (short) 1; // for serialization
public static final short MINOR_VERSION_NUMBER = (short) 1; // for serialization
+ public static final short KIND_SETTERHELPER_SINGLETON = 1;
+ public static final short KIND_SETTERHELPER_ARRAYALL = 2;
+ public static final short KIND_SETTERHELPER_ARRAYITEM = 3;
+
public final Object monitor()
{
if (has_store())
@@ -1999,7 +2003,7 @@
}
if (obj.isImmutable())
- set(obj.stringValue());
+ setStringValue(obj.getStringValue());
else
{
boolean noSyncThis = preCheck();
@@ -2077,6 +2081,167 @@
return (XmlObject) newObj;
}
+ public final XmlObject generatedSetterHelperImpl(XmlObject src, QName propName, int index,
+ short kindSetterHelper)
+ {
+
+ XmlObjectBase srcObj = underlying(src);
+
+ if (srcObj == null)
+ {
+ synchronized (monitor())
+ {
+ XmlObjectBase target = getTargetForSetter(propName, index, kindSetterHelper);
+ target.setNil();
+ return target;
+ }
+ }
+
+ if (srcObj.isImmutable())
+ {
+ synchronized (monitor())
+ {
+ XmlObjectBase target = getTargetForSetter(propName, index, kindSetterHelper);
+ target.setStringValue(srcObj.getStringValue());
+ return (XmlObject) target;
+ }
+ }
+
+
+ boolean noSyncThis = preCheck();
+ boolean noSyncObj = srcObj.preCheck();
+
+ if (monitor() == srcObj.monitor()) // both are in the same locale
+ {
+ if (noSyncThis) // the locale is not sync
+ {
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ else // the locale is sync
+ {
+ synchronized (monitor())
+ {
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ }
+ }
+
+ // on different locale's
+ if (noSyncThis)
+ {
+ if (noSyncObj) // both unsync
+ {
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ else // only obj is sync
+ {
+ synchronized (srcObj.monitor())
+ {
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ }
+ }
+ else
+ {
+ if (noSyncObj) // only this is sync
+ {
+ synchronized (monitor())
+ {
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ }
+ else // both are sync can't avoid the global lock
+ {
+ boolean acquired = false;
+
+ try
+ {
+ // about to grab two locks: don't deadlock ourselves
+ GlobalLock.acquire();
+ acquired = true;
+
+ synchronized (monitor())
+ {
+ synchronized (srcObj.monitor())
+ {
+ GlobalLock.release();
+ acquired = false;
+
+ return (XmlObject)objSetterHelper(srcObj, propName, index, kindSetterHelper);
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ throw new XmlRuntimeException(e);
+ }
+ finally
+ {
+ if (acquired)
+ GlobalLock.release();
+ }
+ }
+ }
+ }
+
+ private TypeStoreUser objSetterHelper(XmlObjectBase srcObj, QName propName, int index, short kindSetterHelper)
+ {
+ XmlObjectBase target = getTargetForSetter(propName, index, kindSetterHelper);
+
+ target.check_orphaned();
+ srcObj.check_orphaned();
+
+ return target.get_store().copy_contents_from( srcObj.get_store() ).
+ get_store().change_type( srcObj.schemaType() );
+ }
+
+ private XmlObjectBase getTargetForSetter(QName propName, int index, short kindSetterHelper)
+ {
+ switch (kindSetterHelper)
+ {
+ case KIND_SETTERHELPER_SINGLETON:
+ {
+ check_orphaned();
+ XmlObjectBase target = null;
+ target = (XmlObjectBase)get_store().find_element_user(propName, index);
+ if (target == null)
+ {
+ target = (XmlObjectBase)get_store().add_element_user(propName);
+ }
+
+ if (target.isImmutable())
+ throw new IllegalStateException("Cannot set the value of an immutable XmlObject");
+
+ return target;
+ }
+
+ case KIND_SETTERHELPER_ARRAYALL:
+ check_orphaned();
+ //arraySetterHelper(lineItemArray, LINEITEM$4);
+ throw new IllegalArgumentException("Unknown kindSetterHelper: ARRAYALL");
+ //return null;
+
+ case KIND_SETTERHELPER_ARRAYITEM:
+ {
+ check_orphaned();
+ XmlObjectBase target = null;
+ target = (XmlObjectBase)get_store().find_element_user(propName, index);
+ if (target == null)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (target.isImmutable())
+ throw new IllegalStateException("Cannot set the value of an immutable XmlObject");
+
+ return target;
+ }
+
+ default:
+ throw new IllegalArgumentException("Unknown kindSetterHelper: " + kindSetterHelper);
+ }
+ }
+
/**
* Same as set() but unsynchronized.
* Warning: Using this method in mutithreaded environment can cause invalid states.
@@ -2099,8 +2264,13 @@
if (obj.isImmutable())
set(obj.stringValue());
else
- newObj = setterHelper( obj );
+ {
+ check_orphaned();
+ obj.check_orphaned();
+ newObj = get_store().copy_contents_from( obj.get_store() ).
+ get_store().change_type( obj.schemaType() );
+ }
return (XmlObject) newObj;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org