Commit Graph

466 Commits

Author SHA1 Message Date
Jean-Philippe Andre d6d4c3c25b eo: Fix crash in case of API misuse
If efl_object_override() is called with a function that does
not exist in the original class, it may lead to a crash on
indexing an non-existing array in the vtable.

This is really just a safety check, as the usage was wrong:
 * You are only allowed to override functions that are defined in the
 * class or any of its interfaces (that is, efl_isa returning true).
2017-04-18 15:34:29 +09:00
Jean-Philippe Andre 8947caf120 eo: Fix shadow variable warning 2017-02-15 20:11:22 +09:00
Jean-Philippe Andre 63eb9a28b3 eo_debug: Remove some abusive goto where not needed
goto was used for micro-optimization. There is absolutely no
need for those if we're using the slow path with eo_debug.

Simplify the code.
2017-02-15 15:35:38 +09:00
Jean-Philippe Andre a11836b5a1 eo_debug: Some more log improvements
Nothing fancy here...
2017-02-15 15:35:38 +09:00
Jean-Philippe Andre 2e96b5074d eo_debug: Improve dangling xref debug logs even more
In case of manual free, as is heavily used by Evas, we can't really
print an ERR if there are still references before free has been
called.

This may not be ideal from a pure EO point of view but considering
how Evas uses manual free this is the best solution to avoid
polluting debug logs.
2017-02-15 14:50:50 +09:00
Jean-Philippe Andre a5535464bf eo_debug: Improve one log
This changes the following message when the object is referencing
its own data. Also lowers from ERR to WRN and adds the class
name for the referenced data.

ERR<17450>:eo /home/jpeg/e/core/efl/src/lib/eo/eo_private.h:337
  _efl_unref_internal() in /home/jpeg/e/core/efl/src/lib/eo/eo.c:620:
  func '_efl_object_call_end' Data of object 0x400000021008db58 is
  still referenced by object 0x400000021008db58

Note that evas and elm have a few calls to efl_data_ref(obj, NULL)
which are imho quite ugly: not using the return value and not
specifying the data class. I'm keeping them as-is for now.
2017-02-15 14:01:06 +09:00
Carsten Haitzler 6d4b85f820 eo base - fix warnings for debug logs to get format string types happy
gcc is very unhappy with these log prints - specifically on arm 32bit.
this fixes it so we can focus on real warnings/issues.
2017-02-12 00:32:16 +09:00
Gustavo Sverzut Barbieri 3680ae0bab eo_debug: print tracebacks for more errors.
If eo_debug (libeo_dbg/EO_DEBUG), then print tracebacks if lifecycle
is being tracked.
2016-12-20 10:18:31 -02:00
Tom Hacohen 78bbd29720 Eo: remove unreachable code in isa.
This condition can never be true. It can't be NULL here. A NULL here
would have caused a crash earlier, though it can only be NULL if an
allocation fails, which is something that we don't really handle
for smallish allocations.

CID1366823
2016-12-15 11:36:51 +00:00
Gustavo Sverzut Barbieri 87bed5622e eo_lifecycle: on log level info (3), show leaked objects.
Since we keep a log of created and deleted objects, we can walk the
log and see which were leaked. As this is expensive, do only if log
level is greater than 3 (INFO, DEBUG...), with backtrace of object
creation being displayed as backtrace if running as level 4 (DEBUG).
2016-12-08 16:00:01 -02:00
Tom Hacohen 5424cdbd81 Eo: Fix efl_isa() sometimes returning wrong results with extensions
This fixes an issue where efl_isa() wouldn't work for extensions or
ancestors of extensions of a class.

Example:
Class A implements interface F2
F2 inherits from interface F1
obj is of class A

Before this patch efl_isa(obj, F1) would return false, now it returns
true as expected.

This is just one example, there is a whole array of variations to this
issue that are now fixed.

Thanks to Gustavo for reminding me of this.

@fix
2016-12-07 13:55:13 +00:00
Gustavo Sverzut Barbieri 261b0faa54 eo: guard lifecycle obj log inside spinlock.
since the array can be pushed or looked up from multiple threads we
must have a lock in place.
2016-12-06 14:38:34 -02:00
Gustavo Sverzut Barbieri 79d44f212e eo: guard all efl_super() checks under EO_DEBUG.
Tom is worried about performance hit (god, checking a bit in a pointer
we'll fetch to memory anyway, since we return it masked), so guard
under EO_DEBUG.
2016-12-06 14:27:10 -02:00
Gustavo Sverzut Barbieri 0593216995 eo: efl_super() can receive a class as first parameter.
This fixes the src/tests/eo/test_function_overrides
2016-12-06 12:40:33 -02:00
Jean-Philippe Andre 552831386a eo: Fix potential inifinite loop
I saw a little oopsie in patch fc48161910. This
amends it to avoid a potential infinite loop.
2016-12-05 18:40:46 +09:00
Jean-Philippe Andre c6dcf3dda4 eo: Make error message less nebulous
When writing this ERR log I thought about "thread" (it's really
the keyword here) but eventually reworded to "context". Let's be
clearer about the possible issue here.
2016-12-05 09:46:55 +09:00
Gustavo Sverzut Barbieri 9eba6bf2e7 eo: do not use eina_trash when running on valgrind.
This allows valgrind to show when the object was created and deleted.
2016-12-03 10:35:27 -02:00
Gustavo Sverzut Barbieri 2e0fcbe5b4 eo: fix compilation without HAVE_BACKTRACE.
time_get() function was used even in that case to log when objects
were created or deleted.

thanks @vtorri.
2016-12-03 09:44:44 -02:00
Gustavo Sverzut Barbieri 7a1e5923f9 eo: fix missing Evil.h include 2016-12-03 09:41:09 -02:00
Jean Guyomarc'h deda8ac8e7 eo: fix build on macOS
Commit 227463bd introduces macOS-specific code, but without including the
header that provides the used declarations.
2016-12-03 12:10:04 +01:00
Gustavo Sverzut Barbieri 6e8280a540 eo: more information when we cannot resolve method.
_efl_object_api_op_id_get() will query a hash for the given pointer,
however if it wasn't populated, it will return "NOOP" and we're
hopeless while debugging on what happened.

Common case is to use the incorrect method, like:

        obj = efl_add(CLS1, ...);
        cls2_method(obj);

Since we did not create CLS2, it won't populate its methods on the
hash, thus the lookup will return NOOP.

With this change the function now gets the target object and function
name so reports an insightful message such as:

        ERR:eo file.c:123 cls2_method() Unable to resolve op for api func 0x7ff492ddea00 for obj=0x400000007e8ee1df (CLS1)
2016-12-02 21:44:23 -02:00
Gustavo Sverzut Barbieri 227463bdde eo: allow valgrind-like tracking of object lifecycle.
Eo pointer indirection is super nice as it avoids you to access
invalid memory, but this extra checks inhibits valgrind's own tracking
of memory lifecycle, usually it would report when the object was
created and when the object is deleted, both as stack traces.

This commits introduces logging of object creation and destruction
under its own eina_log_domain and controlled by EO_LIFECYCLE_DEBUG and
EO_LIFECYCLE_NO_DEBUG envvars. These will only be available if
compiled with EO_DEBUG, thus shouldn't cause any performance hits on
production code.

Running a bogus app with invalid efl_class_name_get() and double
efl_del() will report as below:

```sh
$ export EO_LIFECYCLE_NO_DEBUG=Efl_Loop_Timer,Efl_Promise,Efl_Future
$ export EO_LIFECYCLE_DEBUG=1
$ export EINA_LOG_LEVELS=eo_lifecycle:4
$ /tmp/bogus_app
DBG:eo_lifecycle lib/eo/eo.c:2712 _eo_log_obj_init() will log all object allocation and free
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Future'
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Promise'
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Loop_Timer'
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35a1aa0 obj_id=0x4000000002cf38ef class=0x563fa35a1450 (Efl_Vpath_Core) [0.0004]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35af8d0 obj_id=0x4000000006cf38f0 class=0x563fa35aecf0 (Efl_Loop) [0.0005]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d61a0 obj_id=0x400000007ecf390e class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0054]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d6470 obj_id=0x4000000082cf390f class=0x563fa35d0d60 (Efl_Net_Dialer_Tcp) [0.0055]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d75b0 obj_id=0x4000000086cf3910 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0056]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d8f70 obj_id=0x400000008acf3911 class=0x563fa35d7860 (Efl_Io_Copier) [0.0057]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35df980 obj_id=0x40000000a6cf3918 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0058]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35dfc30 obj_id=0x40000000aacf3919 class=0x563fa35d7860 (Efl_Io_Copier) [0.0058]

will efl_class_name_get() with invalid handle:

ERR:eo lib/eo/eo.c:1013 efl_class_name_get() Class (0x2000000000000029) is an invalid ref.
ERR:eo_lifecycle lib/eo/eo.c:1013 efl_class_name_get() obj_id=0x2000000000000029 was neither created or deleted (EO_LIFECYCLE_NO_DEBUG='Efl_Loop_Timer,Efl_Promise,Efl_Future').
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35df980 obj_id=0x40000000a6cf3918 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35dfc30 obj_id=0x40000000aacf3919 class=0x563fa35d7860 (Efl_Io_Copier) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d75b0 obj_id=0x4000000086cf3910 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d8f70 obj_id=0x400000008acf3911 class=0x563fa35d7860 (Efl_Io_Copier) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d6470 obj_id=0x4000000082cf390f class=0x563fa35d0d60 (Efl_Net_Dialer_Tcp) [0.0063]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d61a0 obj_id=0x400000007ecf390e class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0063]

will double free:

ERR:eo ../src/lib/eo/efl_object.eo.c:78 efl_del() EOID 0x400000007ecf390e is not a valid object. EOID domain=0, current_domain=0, local_domain=0. EOID generation=2cf390e, id=1f, ref=1, super=0. Thread self=main. Available domains [0 1    ]. Maybe it has been deleted or does not belong to your thread?
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e created obj=0x563fa35d61a0, class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0054s, 0.0009 ago]:
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d0ea: libeo_dbg.so+0x90ea (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6ca62: _efl_add_internal_start+0x1c2 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc95f: bogus_app+0x295f (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0ace7291: __libc_start_main+0xf1 (in /usr/lib/libc.so.6 0x7f2c0acc7000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc48a: _start+0x2a (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e deleted obj=0x563fa35d61a0, class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0063s, 0.0000 ago]:
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d8ba: libeo_dbg.so+0x98ba (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d711: libeo_dbg.so+0x9711 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6beb8: libeo_dbg.so+0x7eb8 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6c06e: _efl_object_call_end+0x4e (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc75725: efl_del+0x105 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dcd54: lt-efl_net_dialer_simple_example+0x2d54 (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0ace7291: __libc_start_main+0xf1 (in /usr/lib/libc.so.6 0x7f2c0acc7000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc48a: _start+0x2a (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e was already deleted 0.0000 seconds ago!
```
2016-12-02 21:15:17 -02:00
Gustavo Sverzut Barbieri fc48161910 eo: check for empty vtable and failed extensions.
if for some reason we fail to validate a class, then we should skip
that extension. This may result in an empty vtable, then check for
that and avoid a crash.

This is very unlike to happen in practice, but I've forced some
validation errors and could get to that.
2016-12-02 21:15:17 -02:00
Gustavo Sverzut Barbieri dfe3a4ad40 eo: improve logs by always showing event source, minor refactor.
Instead of 2 sets of macro, one for HAVE_EO_ID and another without,
use a single set of macros and have the implementation of
_eo_class_pointer_get() and _eo_obj_pointer_get() to do the actual

These functions now take the source information so the logs reflect
that and not always the same function.
2016-12-02 21:15:17 -02:00
Gustavo Sverzut Barbieri 04450c4ee0 eo: if EO_DEBUG, check if efl_super() object 'isa' the given class.
A common error is to copy & paste efl_super() calls and forget to fix
the class. If usin EO_DEBUG, then use efl_isa() to error.
2016-12-02 14:51:18 -02:00
Gustavo Sverzut Barbieri 216e6e51e4 eo: better error reporting, always provide caller/source when available.
_eo_pointer_error() was kinda a bitch to debug as it provided a nice
breakpoint location, but did not provide a good output since the file,
line and function were always the same.

Change that to be a thin wrapper on top of eina_log_vprint(), then we
keep the breakpoint location yet provide useful information.

In that sense, change other error messages so they carry as much
information as possible.
2016-12-02 14:50:45 -02:00
Gustavo Sverzut Barbieri cf5aeb9804 eo: use log domain as soon as it's available. 2016-12-02 14:50:45 -02:00
Jean-Philippe Andre b6fae524ff eo: Improve debug for efl_isa errors from threads 2016-12-02 17:21:47 +09:00
Tom Hacohen 79d76fb25e Eo gdb: add a way to resolve Eo ids from GDB without a running process
Normally when debugging Eo with gdb you can just use any of the internal
eo functions to resolve the id to its internal pointer. However, when
loading a coredump you can't execute any code, not even the id resolve
code.

This change adds a gdb function that resolves the id to its pointer form
without executing any code in the process space. This plugin is
essentially the id resolve code written in python as a gdb function.

Usage:
 Print the pointer:
 (gdb) print $eo_resolve(obj)
 $1 = (_Eo_Object *) 0x5555559bbe70

 Use it directly (e.g. to print the class name):
 (gdb) $eo_resolve(obj)->klass->desc.name

This plugin requires that the coredump would be loaded with the exact
same libeo.so binary (or at least one that hasn't changed eo internals),
and that the debug symbols for libeo.so would be available for gdb to
use.

Note:
This feature is incomplete and only resolves IDs that are owned by the
main thread and in the main domain. This is not a big issue at the
moment, because almost all of our IDs are like that.

@feature
2016-11-18 11:48:07 +00:00
Carsten Haitzler 45771d47ab eo - use free queue for at least some eo core memory and pointers
this should help improve robusteness by keeping memory around for a
bit until the free queue flushes or is full

@feature
2016-11-06 13:13:10 +09:00
Tom Hacohen f736946d10 Eo: Add a method to mark objects for reuse.
This informas eo an object is going to get reused/cached, so eo can
reset the object appropriately.

@feature.
2016-10-28 13:19:10 +01:00
Tom Hacohen 25242e6af9 Eo: Fix references of objects 2016-10-21 15:29:39 +01:00
Tom Hacohen 5a659fafd2 Eo: Fix reference leak when failing to resolve function.
When resolving a function for an object the object would get reference,
and then in some failure cases won't be freed.

I suspect this is a regression following the reshuffling that was done
in that function recently.

Thanks to zmike for investigating and reporting this.

Fixes T4740

@fix
2016-10-19 16:32:16 +01:00
Jean-Philippe Andre 9c95eda748 eo: Fix deadlocks with composite objects
This happens with shared objects.

The situation seems to be:
1. object has composited object a of class A in thread 1
2. call something on object a from thread 2, deadlock
In fact, do anything from thread 2 on a shared object and you deadlock.
2016-10-06 17:57:45 +09:00
Carsten Haitzler 6a5ae00ffa eo - goto-ify a chunk iof code moving debug printfs out of hot paths
this moves a lot of error case handling into goto's so the code gets
out of the hot path and this should help expecially since variou
smacros do things like:

   do { char buf[256]; sprintf(buf, fmt, ptr); _eo_pointer_error(buf); } while (0)

   _Efl_Class *klass; \
   do { \
      klass = _eo_class_pointer_get(klass_id); \
      if (!klass) { \
         _EO_POINTER_ERR("Class (%p) is an invalid ref.", klass_id); \
      return ret; \
   } \
} while (0)

so putting quite a chunk of code inside a rare "if this errors"
handler that will cause l1 cache misses and this we don't want, thus
moving stuff in eo core out of hot paths to cut down on overhead. yes
it might not be pretty but it's kind of the right thing at such a core
level of efl. this also does the same to the eo base class as this is
also going to be relatively hot given it's the core of every other
object.
2016-09-29 17:45:47 +09:00
Carsten Haitzler f387818a55 eo - fix error case lock not unlocking with shared objects from coverity
this fixes CID 1363294
2016-09-29 17:45:47 +09:00
Carsten Haitzler edf6507b9f eo - remove pointless if found by coverity
fix CID 1363295
2016-09-29 17:45:47 +09:00
Carsten Haitzler c43308efb4 eo - silence coverit "leak" on eo init if eoid table tls alloc fails
creating a new tls for the eoid table should just never fail so this
is moot anyway, but it silences CID 1362735
2016-09-29 17:45:47 +09:00
Carsten Haitzler 0f929f5546 eo id and shared domain objects - do locking properly and better
so there were a few issues. one we had a spinlokc on the eoid table
for shared objects AND then had a mutex for accessing those objects
(released on return from any eo function). BUT this missed some funcs
like eo_ref, eo_unref and so on in eo.c ... oops. so fixed. but then i
realized there was a race condition. we locked the eoid table then
unlocked with our pointer THEN locked the sharted object mutex ...
then unlocked it. that was a race condtion gap. so we should share the
same lock anyway - if it's a shared object, grab the shared object
mutex then do a lookup and if the lookup does not fail, KEEP the lock
until it is released by the return from eo function or by some special
macro/funcs that released a matching lock. since its a recursive lock
this is all fine. as its also a universal single lock for all objects
we just need the eoid to know if it's shared and needs locking based
on the domain bits. so now do this locking properly with just a single
mutex, not both a spinlock and mutex and keep the lock around until
totally done with the object. this plugs the race condition holes and
goes from 1 spinlock lock and unlock then a mutex lock and unlokc to
just a single mutex lock and unlock. this means shared objects are
actually truly safe across threads and only have the overhead of a
single recursive mutex to lock and unlock in every api call.
2016-09-28 13:38:46 +09:00
Marcel Hollerbach f63cd63e54 eo: fix headr to header
if you enable EO_DEBUG you cannot build eo, since the field is called
header not headr
2016-09-19 13:25:23 +02:00
Marcel Hollerbach 907bbbf965 eo: fix callback cmp
Summary:
as told in _eina_stringshared_key_cmp in eina_hash.c:

originally we want to do this:
   return key1 - key2;
but since they are ptrs and an int can't store the different of 2 ptrs in
either 32 or 64bit (signed hasn't got enough range for the diff of 2
32bit values regardless of their type... we'd need 33bits or 65bits)

So changing this to the same logic.

Reviewers: tasn, raster

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D4298
2016-09-19 13:25:23 +02:00
Carsten Haitzler 50d508866e eo invalid err - make the thread self more useful like main. 2016-09-17 05:49:32 +09:00
Tom Hacohen cfcdacc5f7 Eo: Remove the EO_DEBUG env check. We have DBG for that. 2016-09-09 11:38:07 +01:00
Tom Hacohen 7ebf9d879d Eo: Change the way functions are registered to classes
This change lets us remove a field from the structure that leads to
around 20KiB more of saving in private dirty pages in elementary.

This also looks a bit better and feels a bit cleaner.

Breaks API and ABI.
2016-09-09 11:14:35 +01:00
Tom Hacohen 5ad71f1486 Eo: don't allow object override to introduce previously undefined functions. 2016-09-09 11:14:05 +01:00
Carsten Haitzler 8b159aab68 eo - move eoid lookup to ptr indir file and clean up some code
this improves the readability of some of the new domain related and
ptr indir code..
2016-09-09 18:53:20 +09:00
Carsten Haitzler 54c39aa564 eo class add - dont always call getenv as this is epxensive. get once
so class creation is possibly a little slower thanks to always calling
getenv. get once then store rsult from there on out.
2016-09-09 18:53:20 +09:00
Cedric BAIL 9a2ada6d87 eo: add abstract efl.future. 2016-09-08 14:58:05 -07:00
Tom Hacohen bd3801247e Eo: Make function overrides implicit.
Before this commit, function overrides were explicit. That is, you'd
have to explicitly state you were overriding a function instead of
creating a new one. This made the code a tad more complex, and was also
a bit more annoying to use. This commit removes this extra piece of
information.

This means we now store much less information per function, that will
let us further optimise out structures in the future.
2016-09-08 13:59:04 +01:00
Tom Hacohen 6b60560773 Eo class creation: Simplify code using recursive locks.
Now that we have recursive locks, the class creation code can be much simpler.
All the code there was essentially our own implementation of recursive locks,
or rather a special case of those.

This is no longer needed.
2016-09-08 11:14:32 +01:00
Carsten Haitzler 3ce5d1ebc7 eo_compatible - improve usability of err/warnings by duplication impl 2016-09-08 00:09:32 +09:00
Carsten Haitzler 9d2786896b eo - fix indenting in a file that was nuts and non-standard 2016-09-08 00:09:31 +09:00
Carsten Haitzler f695762d06 eo - add single global mutex for all shared eo objects to they are th-safe
this adds a signle mutex (recursive) mutex for all eo objects that is
auto-called by _efl_object_call_resolve() and _efl_object_call_end()
that wrap all eo method calls and since its recursive it can be
blindly called for sub-calls. this will lock all shared objects during
any call to any shared object so only the thread calling now has
access until it releases. not fine-grained but good enough and the
best we can do "simplistically".
2016-09-08 00:09:31 +09:00
Carsten Haitzler 09f19c3c73 eo - make eo id table TLS private data for thread safety and speed
This moved all the eoid tables, eoid lookup caches, generation count
information ad eo_isa cache into a TLS segment of memory that is
thread private. There is also a shared domain for EO objects that all
threads can access, but it has an added cost of a lock. This means
objects accessed outside the thread they were created in cannot be
accessed by another thread unless they are adopted in temporarily, or
create4d with the shared domain active at the time of creation. child
objects will use their parent object domain if created with a parent
object passed in. If you were accessing EO (EFL) objects across threads
before then this will actually now cause your code to fail as it was
invalid before to do this as no actual objects were threadsafe in EFL,
so this will force things to "fail early".
ecore_thread_main_loop_begin() and end() still work as this uses the
eo domain adoption features to temporarily adopt a domain during this
section and then return it when done.

This returns speed back to eo brining the overhead in my tests of
lookup for the elm genlist autobounce test in elementary from about
5-7% down to 2.5-2.6%. A steep drop.

This does not mean everything is perfect. Still to do are:

1. Tests in the test suite
2. Some API's to help for sending objects from thread to thread
3. Make the eo call cache TLS data to make it also safe
4. Look at other locks in eo and probably move them to TLS data
5. Make eo resolve and call wrappers that call the real method func do
   recursive mutex wrapping of the given object IF it is a shared object
   to provide threadsafety transparently for shared objects (but adding
   some overhead as a result)
6. Test test est, and that is why this commit is going in now for wider
   testing
7. Decide how to make this work with sending IPC (between threads)
8. Deciding what makes an object sendable (a sendable property in base?)
9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 18:17:10 +09:00
Tom Hacohen 4aae224ef5 Efl object: change the way we set class's functions.
This is another follow up to the investigations of T4227. As stated
there, in any PIE (a shared library is one), structures, even const ones
end up being written to because of dynamic relocation. This means that
using static const structures has actually lead to no savings, only
waste. Since we never really needed them, using them made things even
worse than just having a different API that doesn't save them.

Thus, this commit changes the way we set the functions. Instead of
passing a pre-populated struct, we now just have an initialiser function
where you set the functions. This on its own doesn't significantly reduce
the amount of dirty memory pages for a reason I have yet to uncover,
though I believe it's done as a misguided compiler optimisation.
However, this design is flexible enough so we can change to another one
that is quite ugly, but I have already tested and proven that does that.
This patch series doesn't include the better improvement (passing
        everything on the stack as va_args) because the API was too ugly
for me to bear, and I would rather first make sure there is no way to
force the compiler to do the right thing here.

Unfortunately this commit gives up on useless stricter validation.
Before this commit we would make sure that we are only overriding
functions correctly defined in our hierarchy. With this one, we don't
anymore. This is not a big problem though because this is a check that
is also enforced by Eolian. So as long as you are using Eolian, you
should be fine.

Breaks API and ABI!

@feature
2016-09-05 16:03:17 +01:00
Cedric Bail 05f05dde5c eo: protect efl_isa from thread race condition. 2016-09-02 10:19:45 -07:00
Cedric BAIL 605fec91ee eo: improve speed of walking callback array by sorting them during creation.
This improve speed of processing events in genlist scrolling benchmark by 30%
inside the efl_object_event_callback_call code. Not a really big deal as it
goes from 0.9% to 0.6% of the total time spend. Welcome to micro optimization.
2016-09-02 10:19:45 -07:00
Carsten Haitzler 90acc0216b eo - make eoid table access threadsafe - was missing a lock around it
this now makes at least eoid deref and ojbect access safe across
threads. the downside is that oeid lookup goes from 2% to ~5% of cpu.
ugh.
2016-09-01 18:59:56 +09:00
Cedric BAIL aaa0e962b7 eo: speedup efl_isa by 50%.
Most of our use case of efl_isa is related to legacy Evas_Object_Image API,
that check the isa of the same object again and again. Caching help.
2016-08-26 12:14:14 -07:00
Tom Hacohen b3dd735be7 Efl Object: Change and rename the type we use for function pointers.
Rename the type to something more sensible and change it to remove the
last remanent of Eo1. This fixes a fixme that has been there for a
while.

The type doesn't really matter, it just looks nicer with the va_list.
2016-08-16 16:29:21 +01:00
Tom Hacohen 28c80f9122 Efl object: implement CoW for the function vtables
This commit implements a sort of CoW for the vtables. The vtables are
usually just linked to and refcounted. When we need to change them we
allocate new ones and copy them over so we can write to them.

I wrote some code to measure the effectiveness of this change. When
running elementary_test (and immediately exiting) I saw that out of the
total number of vtable chains (561) that were needed by the classes in
the EFL, 79 (14.08%) were reused. Considering that I had to add
refcounting (unsigned short, but let's consider it's the size of a word
because of alignment), I would calculate the saving as such (in bytes):

Number of items in a chain (refcounted block): 32

32 bit:
sizeof(chain_node) = 8
Mem wasted on refcounting: 561 * 4 = 2244
Mem saved because of sharing: 79 * (32 * 8) = 20224
Total save: 17980 bytes

64 bit:
sizeof(chain_node) = 16
Mem wasted on refcounting: 561 * 8 = 4488
Mem saved because of sharing: 79 * (32 * 16) = 40448
Total save: 35960 bytes

Wow, we use a lot of memory in Eo classes, I'm sure we can
save even more if we put our hearts into it (change the shareable units
        to be smaller to increase the chance of sharing).
This is internal and doesn't affect API/ABI so we can change this even
further with time.

This also improves efl_object_override(). This should now be quite
memory efficient (don't abuse, but it's not a big hogg as it was), so
feel free to abuse that one and rely on it in API.

@feature
2016-08-16 16:29:21 +01:00
Tom Hacohen e65aae994e Eo: Finish the renaming of Eo to the EFL.
This renames all the rest of the API to the EFL namespace except for
Eo_Event that will follow soon.

Obviously breaks both API and ABI.
2016-08-15 15:07:42 +01:00
Tom Hacohen c662934be8 Change the EFL to follow the new Eo rename. 2016-08-11 17:04:43 +01:00
Tom Hacohen e64e120a51 Eo: Rename most of Eo to the Efl prefix.
This includes Eo.Base -> Efl.Object and many (but not all) of the eo
functions. This commit is only for eo itself, not the rest of the EFL.
2016-08-11 17:04:43 +01:00
Carsten Haitzler 742fbc5717 evas canvas destruction - detect zombie objs and hack at them with axes
ok. so here's the issue at least now. we have eo objects in the canvas
and they have a refcount of 2 user_refcount is 0. the calls stack does
NOT show we are calling callbacks at that time on these objects. they
are not in the backtrace (the canvas is, the objects themselves are
not).

SOMETHING is keeping 2 eo "internal" refs on these objects and i have
no idea what/how/who. it's a royal pain in the butt to find out as the
only way is lots and lots of logging and you get drowned in the
logging...

so what I have now done is a super ugly workaround that detects these
zombie objects that refuse to die and just FORCES them to die when the
evas canvas frees and clears out layers.
ac10a00acc doesn't really cause the
issue, it just brings it out in the open for all to see far more
easily. but something is deeply wrong SOMEWHERE with SOME objects and
our refcounts.

this fixes T4187
2016-07-29 00:02:03 +09:00
Jean-Philippe Andre 6a559a6fff eo: Prevent eo_override to be called on an already overridden object
I don't see the point of it but can't be bothered to argue.
For Tom.
2016-07-21 13:49:37 +09:00
Jean-Philippe Andre 3029227fa1 eo: Change eo_override to avoid struct passing and GCC construct
This is a (minor) API & ABI break in Eo.h!

I say minor as eo_override shouldn't be used yet (EO is unstable
and this patch includes all the use cases in EFL).

I'm not very happy about the new form of the macro, but it avoids
two things:
- passing in a struct (valid in C, but never used in EFL)
- using a GCC construct to create structs on the fly

It was inspired by the event array define, but I don't think
we need the runtime memcpy here.

See also:
https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
2016-07-19 17:55:07 +09:00
Jean-Philippe Andre cae939e208 eo: Fix leak in eo_override and allow NULL to reset
eo_override would leak the vtable if called multiple times, this
fixes that. Also, it is now possible to revert back to the original
class' vtable by passing in { NULL, 0 }

I believe it is thus possible to incrementally override more
functions on an object. Absolutely not recommended, but should work.
But it is not possible to selectively revert back to the original
class implementation on a single method. Use eo_super for that,
or revert back the entire object overrides.

PS: Is it normal that we pass in a struct? We never do that in EFL...
2016-07-18 17:55:58 +09:00
Tom Hacohen fdc0eef770 Eo add ref: Fix a bug causing leaks and wrong refcount in some cases.
When using eo_add_ref, it was increasing the refcount before the user
context in the addition has fully ended. This means the object had its
reference increased while still not finalized, which means it was
sometimes passed with an increased refcount to unsuspecting class code.
The correct behaviour is to increase the reference count just before
returning the object to the user at the end of eo_add so the reference
count is only increased for whoever asked for it.

Breaks ABI!

@fix
2016-07-12 11:09:40 +01:00
Tom Hacohen a5eb66edd4 Eo refcount: Split the refcount to private and public (user).
This commit changes the way refcount is dealt with internally. Before
this commit, there was one refcount shared between Eo internals and
users. Now there is a refcount for eo operations (like for example,
function calls) and one for user refcount (eo_ref).

An example bug that this protects against (which is seemingly rather
common) is:
some_eo_func(obj);

// Inside the implementation of that func:
pd->a = 1; // The object's private data
eo_unref(obj); // To delete the object
eo_unref(obj); // A big one extra unref
pd->a = 2; // Segfault, this data has already been freed

This is a feature, but really just a fix for a class of bugs.

@feature
2016-07-12 11:09:40 +01:00
Jean-Philippe Andre 85a9bd5430 eo: Fix crash during eo_shutdown
I was getting a crash in eo_shutdown, inside
_efl_event_pointer_class_destructor as I was calling eo_del
from there. But the parent class was already destroyed.

Assuming class IDs can only go up, and child classes are only
instanciated after all their parents, it is safer to call the
class destructors in reverse order.

Obviously, still pretty sure eo_del() in a class_destructor
is not a good idea...
2016-07-05 19:15:13 +09:00
Stefan Schmidt ecdbde7493 eo: remove now longer needed EO_BASE_BETA define from code base
This was needed when the eo composite object was still in beta. Since commit
d7c45e41d4 this is no longer the case. No beta
part left in eo base so we can safely remove this define.
2016-06-20 10:07:30 +02:00
Tom Hacohen f122437dd6 Eo: fix reference hack when calling composite objects.
We used to keep a reference to the parent object and have it in the call
structure although we were actually calling the function on the embedded
object. This was needed because we wanted to unref the parent correctly.
This was incorrect (and marked as a hack) and now I finally gotten
around to implementing the (amazingly simple) fix to remove this
workaround.

Essentially we just ref the comp object, unref the parent, and let the
normal eo call flow to unref the comp object correctly later on, like it
would have unreffed the extra ref we had for the parent.
2016-06-05 15:22:53 +01:00
Tom Hacohen a6a2338962 Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba.

It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.

We would have an issue with references and objects being freed too soon
and in general, issue with the references.

Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.

eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 13:33:21 +01:00
Carsten Haitzler 11393cfee3 Revert "eo - now ref and unref objects on each eo call to keep things safe"
This reverts commit 4044fe6504.
2016-05-25 17:35:53 +09:00
Carsten Haitzler 4044fe6504 eo - now ref and unref objects on each eo call to keep things safe
so... i got this ... callback calls callback calls something calls
callback that deletes the original object at the top so when it comes
back ... things die as the object was destructed. in removing eo_do()
we removed the ref/unrefs that went with it. so this uses the
_EO_API_BEFORE_HOOK and _EO_API_AFTER_HOOK to call exposed "internal"
public functions _eo_real_ref() and _eo_real_unref().

this fixes a new segv i've noticed in several e dialogs where hitting
close does the above via callbacks and closes the window etc.
2016-05-24 09:20:49 +09:00
Tom Hacohen 83a2ed5e70 Eo: Fix wrong allocation.
We weren't allocating the correct amount. Oops.

CID 1355594.
2016-05-23 08:36:16 +01:00
Tom Hacohen 5e95d7f2d8 Eo super: Validate class in eo_super instead of call_reslove.
This is more correct and fixes a segfault that occurs when eo_id is
disabled.
2016-05-20 11:47:32 +01:00
Tom Hacohen 06f65ab2b1 Eo: Implement eo_override() to enable overriding functions of objects.
This change lets you override the functions of objects so that those
functions will be called instead of the functions of the class. This
lets you change objects on the fly and makes using the delegate pattern
easier (no need to create a class every time anymore).
You can see the newly added tests (in this commit) for usage examples.

@feature
2016-05-20 10:25:00 +01:00
Tom Hacohen c450efdcde Eo: Improve error message when overriding functions. 2016-05-20 10:25:00 +01:00
Tom Hacohen e1efe2e651 Eo: Reorganise the vtable in classes and add pointer from objects.
This is the first step towards supporting eo_override().
More details about eo_override() to follow.
2016-05-20 10:25:00 +01:00
Carsten Haitzler 72adab7222 eo datarefcount - only use in debug mode 2016-05-18 23:11:00 +09:00
Tom Hacohen 96624b9725 Eo: Fix singleton pattern and add a test to make sure it works. 2016-05-18 13:31:30 +01:00
Tom Hacohen 546ff7bbba Eo: Remove eo_del() and make eo_unref() the replacement.
We used to have eo_del() as the mirrored action to eo_add(). No longer,
now you just always eo_unref() to delete an object. This change makes it
so the reference of the parent is shared with the reference the
programmer has. So eo_parent_set(obj, NULL) can free an object, and so
does eo_unref() (even if there is a parent).

This means Eo no longer complains if you have a parent during deletion.
2016-05-17 16:23:23 +01:00
Tom Hacohen 9ef65788f4 Eo: Rename an internal function to reduce confusion.
@raster added eo_id_get() which was confusing because we already had
_eo_id_get() that was used internally.
2016-05-17 10:29:16 +01:00
Tom Hacohen 6cacef2503 Eo abstract class: Rename to Eo.Class. 2016-05-12 14:33:40 +01:00
Tom Hacohen 106951a61d Eo: Make eo_del() an eo function.
This was done following a feature request by @raster. There was no real
reason for it not to be an eo function and this gives us more
flexibility.

The reason why this done was to provide a way for classes to do special
things when an object deletion was requested, for example in the case of
Evas, hide the object.
2016-04-26 16:29:18 +01:00
Carsten Haitzler 09cdd364f9 eo - class table - move to mmaped memory if possible and alloc chunks
so memory for class id -> ptrs is mallocs. this means it likely will
be next to other memory malloced. which means overrunning memory
someone mallocs could walk into the class table and corrupt it. we put
eo ids in mmaped regions to avoid this if possible in case of buggy
code. let's do it for classes too.

this also now allocs in larger chunks. for mmap its in page chunks
(which can hold either 1024 or 512 classes depending on 32 or 64bit).
reallocs still work if mmap is not there and we do them in chunks of
128 classes (it seems that we start at about 70 or so classes atm when
elm_test starts and it grows to ~100 or let's do 128 as that's pretty
much our base as a power of 2 and we now dont realloc much).
2016-04-24 12:07:42 +09:00
Tom Hacohen c9347b1ca2 Revert "Eo: Fix rare crash after call_resolve"
I'm reverting this because according to jpeg it was possibly fixed in
5284b62e93.
I reverted this patch after his fix and followed his reproduction cases
and it seems that his second patch does indeed fix this issue so this
patch is no longer needed.

This reverts commit 0862b9d083.
2016-04-06 11:18:36 +01:00
Jean-Philippe Andre 0862b9d083 Eo: Fix rare crash after call_resolve
It seems that calling a @class function with an EO object
(that was not the required Eo_Class) lead to a situation
where func->func was NULL. And that meant a crash after
call_resolve.

The proper fix is to properly call a @class function with a
class object.
2016-04-06 13:27:04 +09:00
Tom Hacohen 4a75116cb4 Eo: Implement the fallback eo_add implementation.
The current eo_add uses a (very useful) gcc extension that is only
available in gcc compatible compilers (e.g clang). Until this commit we
just temporarily ignored this fact. This adds a fallback implementation that
can be used interchangeably with the non portable one. This means that the
same binary can call either at any point in time and the code will work.

Breaks ABI.
2016-03-29 16:01:52 +01:00
Carsten Haitzler 3df71ab0f6 eo del interceptor: add the ability to intercept deletions of eo objects
Imagine this. You have an object. You pass this object handle as a
message to another thread. Let's say it's not a UI object, so
something you might expect to be able to be accessed from multiple
threads. In order to keep the object alive you eo_ref() it when
placing the message on a queue and eo_unref() it once the message is
"done" in the other thread. If the original sender unref()ed the
object before the message is done, then the object will be destroyed
in the reciever thread. This is bad for objects "expecting" not to be
destroyed outside their owning thread.

This allows thius situation to be fixed. A constructor in a class of
an object can set up a delete interceptor. For example if we have a
"loop ownership" class you multi-ple-inherit from/use as a mixin. This
class will set up the interceptor to ensure that on destruction if
pthread_self() != owning loop thread id, then add object to "delete
me" queue on the owning loop and wake it up. the owning loop thread
will wake up and then process this queue and delete the queued objects
nicely and safely within the "owning context".

This can also be used in this same manner to defer deletion within a
loop "until later" in the same delete_me queue.

You can even use this as a caching mechanism for objects to prevernt
their actual destruction and instead place them in a cached area to be
picked from at a later date.

The uses are many for this and this is a basic building block for
future EFL features like generic messages where a message payload
could be an eo object and thus the above loop onwership issue can
happen and needs fixing.

This adds APIs, implementation, documentation (doxy reference) and tests.

@feature
2016-03-08 16:57:22 +09:00
Tom Hacohen b55ec7a34e Eo: remove the long deprecated eo_data_get.
It has been deprecated for a while, and now it's time to actually stop
using it.
2016-03-04 14:23:02 +00:00
Tom Hacohen d2f799e4cb Eo: Remove useless safety checks.
Those can never happen, ever.
2016-03-04 14:09:34 +00:00
Tom Hacohen fc88037977 Eo: Migrate to the new syntax (Eo 4).
The syntax is described in: https://phab.enlightenment.org/w/eo/

Summary:
eo_do(obj, a_set(1)) -> a_set(obj, 1)
eo_do_super(obj, CLASS, a_set(1)) -> a_set(eo_super(obj, CLASS), 1)

eo_do_*_ret() set of functions are no longer needed.

This is the first step, the next step would be to also fix up eo_add()
which currently still uses the old syntax and is not 100% portable.

@feature
2016-03-03 09:53:23 +00:00
Tom Hacohen 668fd4a6e8 Eo: add support for initialising eo after it has been shut down.
Until now it wasn't allowed/possible to init (eo_init) eo after it has
been shut down (eo_shutdown). This commit fixes that, so now that is
fully legal to have as many init/shutdown cycles as you want.

There was a previous workaround for this issue:
e47edc250d.

This should allow more flexibility when using the EFL in loadable
modules and in various other scenarios.

The problem is that the class_get() functions cache the previously
created class for efficiency, but the class is freed if eo is shut down,
so the cached pointer is actually invalid.
The solution to the problem was to maintain a generation count
(incremented every time we shut down eo), and compare that to a locally
saved version in class_get(). If they don't match, recreate the class,
as it has already been freed.

@feature
2016-02-04 09:27:15 +00:00
Tom Hacohen 43d05a334d Revert "Eo: Prevent shutdown from actually doing anything"
This commit was a workaround to let us shutdown and then init eo without
any issues. It leaks and it's wrong. This will properly be fixed in the
next commit.

This reverts commit e47edc250d.
2016-02-04 09:27:15 +00:00
Tom Hacohen d01ed68825 Eo: fix eo_shutdown()'s return value to be FALSE on shutdown.
The return value of init/shutdown is true if eo is init, false otherwise.
This was broken until now.

@fix.
2016-02-03 16:56:15 +00:00
Tom Hacohen 0ff1646871 Eo: Rearrange class creation code a bit.
This is not really needed, I just did it to make it easier for coverity
(and future static analysers) to understand that the class id doesn't
need to be accessed with a lock.

CID1341854
2016-01-07 13:04:12 +00:00
Vincent Torri 47ed848a87 Evil: integrate the dlfcn code into Evil
This will remove some incompatibilities with other packages,
especially for win-builds
2015-12-29 22:13:58 +09:00
Jean-Philippe Andre e47edc250d Eo: Prevent shutdown from actually doing anything
Currently, eo_shutdown can't work.

Every Eo_Class ID is stored inside its class_get() function as a
static variable. This means any call to class_get() after eo_shutdown()
(even if eo_init was done properly) will lead to using an invalid ref
for the class id. In other words, the class is not valid anymore,
and objects can't be created.

Resetting the pointer to NULL would be possible, if we passed it
during the class creation. But this would lead to potential crashes
if a class was created from a now dlclosed library.

The only solution I can envision here is to check that class_get
actually returns a valid ref with the right class name. Most likely
the performance impact is not acceptable.

This fixes make check for me (with systemd module for ecore).
2015-12-29 20:55:50 +09:00
Tom Hacohen 0bebaed0ac Eo do: use the __thread directive when available to manage call stack.
This is faster in most cases, and to be honest, should be much faster
than it is. I don't understand why there's no better directive to mark a
variable as *really* important thread storage that is used all the time.
2015-11-09 11:43:04 +00:00
Tom Hacohen 3e40b45be6 Eo: Remove extra paranoid-never could happen safety checks.
I was not able to reach those without arbitrary memory corruption, but
in that case we are in trouble anyway.
2015-11-09 11:43:04 +00:00
Tom Hacohen 6ed69b1d11 Eo: Reorganise some of the code and cleanup.
This is cleaner and makes more sense.
2015-11-09 11:43:04 +00:00
Tom Hacohen 3782931c50 Eo: Removed weird unneeded condition. 2015-11-09 11:43:04 +00:00
Tom Hacohen f28f6ecbfa Eo: Move op resolve check to where it belongs (out of hot path).
It was put in the wrong place. It should abort early if it detects we
can't resolve, and shouldn't check it if we already know it's OK.
2015-11-09 11:43:04 +00:00
Tom Hacohen f7f7fc69cf Eo: Split object checking from class checking and simplify.
The check there was wrong for objects anyway, and was ultra conservative
for classes.
2015-11-09 11:43:04 +00:00
Tom Hacohen 680388472e Eo: Reduce call stack memory footprint.
We don't really need the eo_id most of the time, and when we do, it's
very easy to get it. It's better if we just don't save the eo_id on the
stack, and just save if it's an object or a class instead.
2015-11-09 11:43:04 +00:00
Tom Hacohen adbc534703 Eo: Remove useless optimisation that is more harm than good.
It seems that the idea behind that optimisation, is to save object data
fetching when calling functions implemented by the object's class inside
functions implemented by the object's class. This should be rare enough
not to worth the upkeep, memory reads and memory writes, especially
since for all cases apart of mixins (for which this optimisation won't
work for anyway), the upkeep is more costly than fetching the data
again.
2015-11-09 11:43:04 +00:00
Tom Hacohen 748b90d295 Eo: use correct mask when checking if an id is a class 2015-11-09 11:43:04 +00:00
Tom Hacohen 44ca3a3669 Eo: Optimise object data fetching a bit more.
Removed safety check that is not necessary. This may seem small,
but this in addition to the previous commit, account for around
2% of CPU usage.
2015-11-09 11:43:04 +00:00
Tom Hacohen 1ed0edfb9e Eo: Optimise object data fetching (minor).
Pre-calculate object data offset for improved performance.
2015-11-09 11:43:04 +00:00
Carsten Haitzler c2b4137f77 eo - move cache lookup into the hot path if as it only is valid there
minor speedup ... really minor - but correct.
2015-10-24 12:23:53 +09:00
Carsten Haitzler 29884844d4 efl eo - pass test suite function overrides again after adding cache
removing the klass member meant removing hooks and keeping cache small
but that meant not using it. this meand if the object is not an obj...
i removed the:

call->obj = _eo_class_id_get(call->klass);

line - seemed harmless/pointless. apparently not. so put it back but
use the klass there in local vars and not in call as it's not there
(and not needed).

fix.
2015-10-22 09:35:11 +09:00
Carsten Haitzler 8b48906401 eo - oops remove warning cpp i accidentally put in! 2015-10-21 22:27:06 +09:00
Carsten Haitzler 9ef9f2deb8 eo resolv cache - remove params passed to resolv func for efficiency
we pass both the callcache and the op id - both are static and filled
in at runtime, so merge them into the same struct. this should lead to
better alignment/padding with the offset array and the next slot and
op fields, probably saving about 4-8 bytes of rame per method with no
downsides. also pass in only cache ptr, not both cache ptr and opid -
less passing of stuff around and should be better.
2015-10-21 22:23:18 +09:00
Carsten Haitzler 7cc41473a3 efl - eo - massively improve eo cal resolv and data scope get with cache
BEWARE! this breaks eo ABI. _eo_call_resolve and _eo_data_scope_get
are 2 of the biggest cpu users in eo. they easily consume like 10-15%
cpu between them on tests that drive a lot of api - like simply
scrolling a genlist around. this is a lot of overhead for efl. this
fixes that to make them far leaner. In fact this got an overall 10%
cpu usage drop and that includes all of the actual rendering, and code
work, so this would drop the eo overhead of these functions incredibly
low. using this much cpu just on doing call marshalling is a bug and
thus - this is a fix, but ... with an abi break to boot. more abi
breaks may happen before release to try and get them all in this
release so we don't have to do them again later.

note i actually tested 4, 3, 2, and 1 cache slots, and 1 was the
fastest. 2 was very close behind and then it got worse. all were
better than with no cache though.

benchmark test method:

export ELM_ENGINE=gl
export ELM_TEST_AUTOBOUNCE=1

while [ 1 ]; do sync; sync; sync; time elementary_test -to genlist;
sleep 1; done

take the 2nd to the 8th results (7 runs) and total up system and user
time. copmpare this to the same without the cache. with the cache cpu
time used is 90.3% of the cpu time used without - thus a win. at least
in my tests.

@fix
2015-10-21 20:16:06 +09:00
Carsten Haitzler 94ebd96df5 eo - another 1.5 percent speedup in eo_bench eo_do by removing err handl
so we do a bit of error handling like does a stack fail to allocate,
does setting the tls var fail, have the stack frames been nulled or
not allocated, etc. - these acutally cost every call because they mean
some extra compare and branches, but ore because they cause a lot fo
extra code to be generated, thus polluting instruction cache with code
and cacheline fetches of code that we rarely take - if ever.

every if () and DBG, ERR etc. does cost something. in really hotpath
code like this, i think it's best we realize that these checks will
basically never be triggered, because if a stack fails to grow... we
likely alreayd blew our REAL stack for the C/C++ side and that can't
allocate anymore and has already just crashed (no magic message there -
just segv). so in this case i think this checking is pointless and
just costs us rather than gets us anything.
2015-10-17 11:42:46 +09:00
Tom Hacohen 07ea62419a Eo do: Reuse stack fetching across eo functions.
This causes a significant speed up (around 10% here) and is definitely
worth it. The way it's done lets the compiler cache the value across
different eo_do calls, and across the parts of eo_do. Start and end.

This breaks ABI.
2015-10-16 16:38:46 +01:00
Tom Hacohen 3ee44dcef0 Eo do: optimise getting the thread call stack for the main loop thread.
This may look like an insignificant change, but it doubles the speed of
this function, and since this function is called so often, it actually
improves my benchmarks by around 8%.
2015-10-16 16:38:44 +01:00
Tom Hacohen b61556aa87 Eo: Move mainloop checks inside Eo.
This breaks ABI in a harmless way, and it will give us the ability to
drastically improve Eo in the future without breaking ABI again, thus
allowing us to declare Eo stable for this release if we choose to.
2015-10-16 14:53:22 +01:00
Tom Hacohen 535076f425 Eo: Fix confusing indentation and style. 2015-10-14 20:43:07 +01:00
Tom Hacohen fd61ff69b3 Eo: Fix Eo on Windows.
We use function names instead of function pointers of Windows, because
of dll import/export issues (more in a comment in eo.c). Before this
commit we were comparing the pointers to the strings instead of the
content in some of the places, which caused op desc lookup not to work.
This fixes that.

Thanks to vtorri for his assistance.

@fix
2015-10-09 12:18:30 +01:00
Tom Hacohen 6a4c603e0f Eo: Remove dead code.
This removes code that became dead in commit:
389c6d35f2
The commit doesn't explain why we don't shrink or grow when using mmap,
but this is how it is. No reason to keep old code there.

CID 1240224

@fix
2015-10-04 15:01:27 +01:00
Tom Hacohen 001aa98942 Eo: Clean up windows code a bit more.
Merge more parts of it with the non-windows code.
2015-09-30 08:38:47 +01:00
Tom Hacohen e2344b9b9e Eo: reduce memory usage across applications.
As described by Carsten in his email to edev ML titled:
"[E-devel] eo stability - i think we need to postpone that"
with the switch to Eo2 we significantly increased our usage of RW memory
pages, and thus significantly increased our memory usage when running
multiple applications.

The problem was that during the migration to Eo2 the op id cache and the
op description arrays were merged, causing the op description arrays to
no longer be RO. This patch enables users of Eo (mainly Eolian) to
declare those arrays as const (RO) again, saving that memory.

There might be performance implications with this patch. I had to remove
the op desc array sorting, and I used a hash table for the lookup. I
think the op desc sorting doesn't really affect performance because that
array is seldom accessed and is usually pretty short. The hash table
is not a problem either, because it's  behind the scenes, so it can be
changed to a more efficient data structure if the hash table is not good
enough. The hash table itself is also rarely accessed, so it's mostly
about memory.

Please keep an eye for any bugs, performance or excessive memory usage.
I believe this should be better on all fronts.

This commit *BREAKS ABI*.

@fix
2015-09-28 18:39:15 +01:00
Tom Hacohen 9328524da4 Eo: Remove EO_SENTINEL.
This was never really needed because we always had the count.
Removing this now because we are already breaking API and ABI.
2015-09-28 15:52:50 +01:00
Tom Hacohen 35a482141d Eo: Clean up windows code.
We were keeping a struct member that wasn't really needed on windows.
Since we already broke ABI, we can afford to clean this up.
2015-09-28 15:26:51 +01:00
Tom Hacohen 12c3986866 Eo: Fix eo function name getter on windows. 2015-09-28 15:24:44 +01:00
Tom Hacohen 37f84b7e96 Eo: Drop doc field from ops and events.
This hasn't been used for a while. Since we are going to break Eo a bit anyway
it's a good opportunity to drop this.

This may cause a slight performance issues with legacy events, such as
smart callbacks. This shouldn't really be a problem as we've migrated away from
them. If it does, we need to migrate the remaining parts. Only relevant
for callbacks that are added before the classes are created, which
shouldn't be possible except for smart, only for old evas callbacks.
2015-09-28 15:09:16 +01:00
Tom Hacohen acc158a2bf Revert "Revert "Eo base: Change parent_set to be an assignment of ref.""
Had to revert it until I pushed the changes to elm, which I had issues
with. Now the patch can safely go back in.

This reverts commit 37abea3831.
2015-08-26 10:47:06 +01:00
Tom Hacohen 37abea3831 Revert "Eo base: Change parent_set to be an assignment of ref."
Damn, this breaks some things. Reverting until fixed.

This reverts commit 9c78ee0bf4.
2015-08-26 10:33:24 +01:00
Tom Hacohen 9c78ee0bf4 Eo base: Change parent_set to be an assignment of ref.
After this change, parent_set assigns a ref, so for example:
  obj = eo_add(CLASS, parent); /* Ref is 1 */
  eo_do(obj, eo_parent_set(parent2)); /* Ref is 1 */
  eo_ref(obj); /* Ref is 2 */
  eo_do(obj, eo_parent_set(NULL)); /* Ref is 1, giving the ref to NULL */
  eo_do(obj, eo_parent_set(parent)); /* Ref is 1 */

This is following a discussion on the ML about commit
8689d54471.

@feature
2015-08-26 10:11:18 +01:00
Carsten Haitzler c6011926ba eo - silence ERR logs on constructor fail - this is valid behavior
@fix

XXX: Given EFL usage of objects, construction is a perfectly valid thing
to do. we shouldn't complain about it as handling a NULL obj creation is
the job of the caller. a perfect example here is ecore_con and ecore_ipc
where you create a con or ipc obj then set up type/destination/port and
the finalize of the constructor does the actual connect and thus this
fails or succeeds based on if service is there.

until there is a better solution - don't complain here.
2015-06-24 19:28:04 +09:00
Tom Hacohen db6c17627f Eo: Fix windows support.
This is heavily based on a patch by Vincent Torri. I just refactored it
a bit so it doesn't break ABI on Linux, only on Windows (where it was
broken anyway).

This patch changes things so on Windows, functions are looked up only
based on their name. Because of the indirection (and export/import
tables) windows does, this is the only reasonable way to make it work.
2015-06-18 14:23:08 +01:00
Tom Hacohen d85029a5c0 Eo: Fix a potentially dangerous lack of {}.
You should always use curly brackets. Especially when the inside statement
has its own curlys. This can be confusing and has already lead to bugs in
many projects.
2015-06-18 14:23:08 +01:00
Tom Hacohen 293d286977 Eo: rename conflicting internal Eo_Base to Eo_Header
This name conflicts with the class Eo.Base and should have
been called Eo_Header from the start anyway.
2015-05-28 17:47:59 +01:00
Tom Hacohen 1d4c028034 Eo: Fix typo in error message.
Thanjs to q66 for reporting.
2015-05-21 10:52:36 +01:00
Tom Hacohen c02bab4149 Eo: Better handle object cleanup on failure.
While unrefing twice works, it's cleaner to unref the ref we
have and delete normally. It will handle parnet detachments in
a nicer way, and is just more correct.
2015-05-20 16:48:33 +01:00
Tom Hacohen 92fb2917cb Eo: Remove eo_error_set() and clean up finalizer()
This is another cleanup in perparation for the Eo stable release.
This is no longer needed thanks to the proper error reporting with
eo_constructor()'s new return value.

The finalizer change cleans it up a bit so it catches more cases/issues.
This also means that the finalizer cleans up the object in all cases,
and not only some.

@feature.
2015-05-20 16:25:38 +01:00
Tom Hacohen 6efbfe227a Eo: Add a return value to eo_constructor().
From now on, constructors should return a value, usually the object
being worked on, or NULL (if the constructor failed). This can also
be used for implementing singletons, by just always returning the same
object from the constructor.

This is one of the final steps towards stabilizing Eo.

@feature
2015-05-20 13:03:24 +01:00
Tom Hacohen e27f40111d Eo: Mark composite APIs as beta.
Until now we used @protected, but now we can finally properly use @beta.
2015-05-08 16:18:36 +01:00
Tom Hacohen 1506ec30ba Eo base: mark composite API as not ready. 2015-05-06 15:46:18 +01:00
Tom Hacohen e891c56f60 Revert "eo: add eo_error_get"
As discussed on IRC and ML. We are in a feature freeze phase, and this
patch is not essential. Furthermore, this patch was never discussed.

This reverts commit 537c7fe9e3.
2015-04-15 08:18:25 +01:00
Jaehwan Kim 537c7fe9e3 eo: add eo_error_get
This is pair of eo_error_set.
2015-04-15 13:57:42 +09:00
Tom Hacohen a791d97bfc Eo: Remove GCCism and make it more portable.
This affects eo_do() and eo_add() that used to use the ({}) GCCism.
Following a discussion with Peter de Ridder after my talk at FOSDEM,
we've decided to reopen the GCCism (works with other gcc compatible
compilers like clang and intelc) discussion, and after a bit of back and
forth it was decided to make things more portable, at the cost of ease
of use.

For example:
if (eo_do(obj, visible_get()))
is no longer allowed, the portable alternative
Eina_Bool tmp;
if (eo_do_ret(obj, tmp, visible_get()))
is to be used instead.

However:
eo_do(obj, a = a_get(), b = b_get(), bool_set(!bool_get))
are still allowed and OK.

eo_do(obj, if (a_get()) return;);
is no longer allowed, but:
eo_do(obj, if (a_get()) something());
is still allowed.

For clarity, this commit only incorporates the Eo changes, and not the
EFL changes to make the efl conform with this change.

Thanks again to Peter de Ridder for triggering this important discussion
which led to this change.
2015-02-23 17:16:02 +00:00
Tom Hacohen 40cb2cd3d4 Eo add: beef up error reporting.
In some cases object ceration would fail without an error,
this is bad and should not happen.

Thanks to cedric for reporting.
2015-01-23 16:51:18 +00:00
Nicolas Aguirre 2982b05288 Eo: use int for _eo_init_count intsead of Eina_Bool 2015-01-12 14:48:22 +01:00
Avi Levin b384cd3f62 eo: Fix bad addressing in _eo_classes array
The header.id was masked before using it as index in the _eo_classes
array and was not unmasked when used.
It hasn't caused segfault (by sheer luck) but was wrong.

@fix
2015-01-08 14:29:07 +00:00
Jérémy Zurcher 18ceed4daf Eo: protect against recursive object destruction calls, fixes T1741
Summary:
    Eo: semantic obj->del replaced by obj->destructed
    Eo: protect against recursive object destruction calls
    Eo: add tests for bfada4b

Reviewers: JackDanielZ, tasn

Reviewed By: tasn

Subscribers: cedric

Maniphest Tasks: T1741

Differential Revision: https://phab.enlightenment.org/D1675

Fixes T1741

@fix
2014-11-18 15:25:34 +00:00