I‘m using db4o for a persistence store in an Android app since db4o allows FREE usage in Android apps I decide it would be a good fit. Until I ran into the an error I could not get around for a couple of weeks.
Over the last couple of weeks I’ve been dealing with an error from hell, the StackOverflowError. I reworked the object model, I cut down the calls, trimmed up all the fat in the Android app I could find and I couldn’t find what was causing the db40 classes to throw a StackOverflow error.
The error that I’d get back would look like this:
06-12 18:31:06.630: DEBUG/dalvikvm(17018): newInstance failed: no () 06-12 18:31:06.640: INFO/dalvikvm(17018): Stack overflow, expanding (0x41869200 to 0x41869000) 06-12 18:31:06.640: INFO/dalvikvm(17018): Shrank stack (to 0x41869200, curFrame is 0x41869698) 06-12 18:31:06.640: DEBUG/AndroidRuntime(17018): Shutting down VM 06-12 18:31:06.640: WARN/dalvikvm(17018): threadid=3: thread exiting with uncaught exception (group=0x4001b180) 06-12 18:31:06.690: DEBUG/dalvikvm(17018): GC freed 5995 objects / 562312 bytes in 36ms 06-12 18:31:06.800: DEBUG/dalvikvm(17018): GC freed 3836 objects / 436456 bytes in 79ms 06-12 18:31:06.840: DEBUG/dalvikvm(17018): GC freed 687 objects / 167288 bytes in 33ms 06-12 18:31:06.860: ERROR/AndroidRuntime(17018): Uncaught handler: thread main exiting due to uncaught exception 06-12 18:31:07.020: DEBUG/Gmail(140): MailEngine.sendOrSaveMessage messageId=1338387167469109248 refMessageId=0, conversationId=1338387167469109248 06-12 18:31:07.030: WARN/ActivityManager(76): Activity pause timeout for HistoryRecord{449684b8 com.google.android.gm/.ComposeActivity} 06-12 18:31:07.090: DEBUG/dalvikvm(17018): GC freed 3055 objects / 566504 bytes in 215ms 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): java.lang.StackOverflowError 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.foundation.CircularLongBuffer4.remove(CircularLongBuffer4.java:73) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.caching.LRU2QLongCache.produce(LRU2QLongCache.java:40) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.caching.LRU2QLongCache.produce(LRU2QLongCache.java:14) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.io.CachingBin.getPage(CachingBin.java:153) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.io.CachingBin.readInternal(CachingBin.java:65) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.io.CachingBin.read(CachingBin.java:57) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.io.BinDecorator.read(BinDecorator.java:40) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.io.BlockAwareBin.blockRead(BlockAwareBin.java:90) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.IoAdaptedObjectContainer.readBytes(IoAdaptedObjectContainer.java:210) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.IoAdaptedObjectContainer.readBytes(IoAdaptedObjectContainer.java:201) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.LocalTransaction.readPointer(LocalTransaction.java:387) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.LocalTransaction.getCurrentSlotOfID(LocalTransaction.java:355) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.LocalObjectContainer.readReaderOrWriterByID(LocalObjectContainer.java:437) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.LocalObjectContainer.readReaderByID(LocalObjectContainer.java:415) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.LocalObjectContainer.readReaderByID(LocalObjectContainer.java:419) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.UnmarshallingContext.readBuffer(UnmarshallingContext.java:127) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:40) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.ObjectReference.read(ObjectReference.java:304) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.ObjectReference.read(ObjectReference.java:290) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.ObjectContainerBase.getHardObjectReferenceById(ObjectContainerBase.java:956) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.classMetadataForObjectId(AbstractReadContext.java:85) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:57) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:46) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:172) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.Handlers4.readValueType(Handlers4.java:313) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext$1.run(AbstractReadContext.java:38) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:36) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.handlers.array.ArrayHandler.readInto(ArrayHandler.java:381) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.handlers.array.ArrayHandler.readElements(ArrayHandler.java:363) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.handlers.array.ArrayHandler.read(ArrayHandler.java:355) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.Handlers4.readValueType(Handlers4.java:313) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:172) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.Handlers4.readValueType(Handlers4.java:313) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext$1.run(AbstractReadContext.java:38) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:36) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.marshall.AbstractReadContext.read(AbstractReadContext.java:28) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.FieldMetadata.read(FieldMetadata.java:811) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:646) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.handlers.StandardReferenceTypeHandler$2.processAspect(StandardReferenceTypeHandler.java:93) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2086) 06-12 18:31:07.100: ERROR/AndroidRuntime(17018): at com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(St
After posting on the forums I was given some advice from Fabio (who looks to be an employee). He advised to try the TransparentActivation mechanism. I implemented it on my 6 classes and in the configuration of db4o as shown in an example in the previous link.
Magically, the error went away. So, if you get this error, implement the Activatable interface (or IActivatable in .NET).
NOTE: This could be vastly useful when Windows Phone 7 is released if you’re using it for .NET.
Rebels says
Awesome!! Thanks for reporting! Could you share a code snippet on how you use Activatable on db4o?
Donn Felker says
I'm just following the example as shown in transparent activation (https://developer.db4o.com/Documentation/Refere…)
Implement Activatable on the class(es) you want to make transparent:
public class Car implements Activatable { }
Implement the required methods. I use the code below on ALL of my classes. Pretty much copy paste job here from class to class.
public void activate(ActivationPurpose purpose) {
if(_activator != null) {
_activator.activate(purpose);
}
}
public void bind(Activator activator) {
if (_activator == activator) {
return;
}
if (activator != null && _activator != null) {
throw new IllegalStateException();
}
_activator = activator;
}
private transient Activator _activator;
Then in each mutator or accessor I activate based upon reading (a get call) or writing (a set call). Example:
// For a read operation
public String getName()
{
activate(ActivationPurpose.READ);
return mName;
}
// and for a write
public String setName(String name)
{
activate(ActivationPurpose.WRITE);
mName = name;
}
Then I just did that for each get/set. After that class was done, I moved onto the next one and did the same exact thing.
– Implement Activatable
– Implement Activation via get/set operations with READ or WRITE Activation purposes.
nike air force 1 says
Yeah,air force 1 shoes I have to admire the landlord's unique point of view,ugg boots for sale this article is very comprehensive and considerable on the analyse, and greatly inspired me. In addition, I would like to share that some other blog's article, content is also very good, if you scan it,there will be a suprise!ugg boots for sale
Evaldas says
Hi, thanks for the suggestions and example. Sometimes db4o makes me scratching my head, and this stack overflow was one of those (looks like this activation may have solved it).
One suggestion thought this works with base class also which would be extended by other domain classes. Would be great if @Activation:disqus , but wouldn’t dare to use that on android for the moment.
You wrote also that db4o is free for android. As I read their license statement they use dual, GPL and some commercial. so does this allow using it for free even if you want to sell the app later on?
Yuehuosudou Sale says
They’re not chosen, so one of these ideal for you. For more flexibleness a lot more like these, there are lots of discount ‘shoulder’ variations outlet louis vuitton uk. The louis vuitton uk are built around the idea of luxury travel, so it follows naturally that it would be particularly suited to a season that came about out of the need for pre-season travel goods for those who have the money and flexibility to escape the winter weather in less exotic locales. amazing beats by dre for those busy days or nights of perfect. headphones handbags outlet fashion handbags and signature characteristics and use of quality fabrics materials. Come to dr dre beats and find brand new beats Factory Shoes Ivory Gray here, which are one of the casual, leisure yet uncommon beats Factory shoes for women on sale. ralph lauren uk is so elegance and perfect that I cant help purchasing one. They are good quality with competitive price and the symbol of elegance. customers are not only interested in handbags and purses, but also fond of?shoes and jewelry which is sold at the coach outlet. Coach is well known for being one of the few American high-end leather goods brands. Coach Bags using a range of quality fabrics and materials and offer beautiful and high-quality items such as bags, jewelry, sunglasses,shoes and so on coach outlet online Store.. coach outlet has become necessary in everyday life of women seeking fashion and simple designs simple and elegant to look at very affordable and practical.