1. A computer implemented method of refactoring software code to optimize execution performance by consolidating shared resources accesses, comprising: using at least one hardware processor for performing the following: receiving a target code containing a plurality of code entries comprising instructions to access at least one of a plurality of shared resources; automatically creating a dependency record for each of said at least one shared resource, said dependency record describes dependencies among at least some of said plurality of code entries accessing at least one shared data items in said at least one shared resource; identifying, based on said dependency record, a resource access point for each of said at least one shared resource, said resource access point is located in an execution path of said target code to precede execution of at least some of said plurality of code entries which use said at least one shared data item and said resource access point follows execution of defining code entries of said plurality of code entries which define said at least one shared data item; automatically refactoring said target code to group together said at least some code entries which use said at least one shared data item, said group is placed following said resource access point to consolidate shared resource accesses of said at least some code entries to said at least one shared resource; and outputting said refactored target code.